Gamestudio Links
Zorro Links
Newest Posts
Question on TMF and WFO training
by Ger1
Today at 11:34
Is Zorro's rollover calculation wrong?
by pcz
Yesterday at 21:30
how can I open a *.dbl file?
by jcl
Yesterday at 19:19
Zelda like games.
by Realspawn
Yesterday at 18:53
Backtesting with T1 data and variable spread
by pcz
Yesterday at 14:12
AUM Magazine
Latest Screens
Triton Wing
ZeaL
Computer Repair Simulator
Collider (working title)
Space Rider
Who's Online
19 registered (kiamonster, Iglarion, boatman, alibaba, jenGs, GreenBoat, kmerlo, Ger1, Dalla, 2 invisible), 520 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
Angeltrader77, Diska, GBA, TomJ, afoluj
17574 Registered Users
Page 5 of 5 < 1 2 3 4 5
Topic Options
Rate This Topic
#464581 - 02/27/17 17:56 Re: Z System result sharing? [Re: RTG]
sodiumchloride Offline
Newbie

Registered: 02/17/17
Posts: 6
SR 0.06, lots of drawdowns but running stable for years - very interesting...

Quote:
"Thatís a robot that looks for short-term divergences Ė in other words, discrepancies between the movement of price and the momentum at which itís moving.
and hes amount of trades is correlated with high volatility."

Top
#464712 - 03/07/17 02:59 Re: Z System result sharing? [Re: sodiumchloride]
RTG Offline
Member

Registered: 02/23/14
Posts: 159
I've found out a little more about this approach from the website. It shouldn't be hard to code this for Zorro and test it.

THE FINCH
The Finch robot looks for divergences on a 5 minute chart. When it finds a divergence, it will take a trade. If the trade is a loser, it will look for one more trade. If that second trade is a loser, the robot will either close all the trades or stay in the trades until they come back (you can tell the robot to choose either style of trading). Most people who buy the robots run Finch on 3-5 currency pairs, and let the robot run on its own.

Top
#464782 - 03/12/17 06:34 Re: Z System result sharing? [Re: RTG]
RTG Offline
Member

Registered: 02/23/14
Posts: 159
Found the MT4 code for what I believe is this system. Seems a bit long complex. I think it would be far shorter in Zorro.

//+------------------------------------------------------------------+
//| Trifecta Automatic.mq4 |
//| Copyright 2015, Rob Booker |
//| http://www.tfl365.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Rob Booker"
#property link "http://www.tfl365.com"
#property version "ao-20160122 21.56"
#property icon "\Images\Rob-Booker_S2-64.ico"
#property description "Added code as preemptive measure to avoid trade timeout error."
#property description "Added code to deal with manually deleted second trade."
#property description "ao-20160105 20.31: with correct magic number EA regains control of"
#property description "its trades. Trade functions repeated after errors."
/*
#property description "ao-20160105 20.31: Reliability enhancement of Rollover Finch v1.9.mq4 from"
#property description "Rollover_Finch_v1.9.zip, available at TFL Membership at /tfl.mykajabi.com."
#property description "Modified init() so EA regains control of trades it made. Make sure you"
#property description "specify the correct Magic number."
#property description "Modified OpenTrade() and CloseAllTrades() so trade functions will repeat"
#property description "if errors occur. Status information and errors are printed in the Experts log"
#property description "to inform you of what's going on."
*/
#property strict

#include <stdlib.mqh>
#include <stderror.mqh>

extern string WARNING = "Using a robot carries risk, use on demo account FIRST";
extern int Slippage=5;
extern int Max_Spread_Pips=5;
extern int Magic = 12345;

extern double First_Trade_Lots=0.05;
extern double Second_Trade_Lots=0.5;

extern int Pips_To_Trade_2 = 10;

extern string Stop_Type="Default no stop loss";
extern int Stop_Loss_In_Pips=0;

extern string Profit_In_Dollars = "Profit Targets in Dollar Value format";
extern double First_Trade_Profit_In_Dollars=10.0;
extern double Second_Trade_Profit_In_Dollars=100.0;

extern bool Break_Even = false;
extern double Break_Even_At_Profit = 50.0;

extern int CandlesBack = 30;
extern int RSIPeriod = 21;
extern int MomentumPeriod = 20;
extern int FastMAPeriod=12;
extern int SlowMAPeriod=26;
extern int SignalMAPeriod=9;
extern int KPeriod=70;
extern int DPeriod=10;
extern int Slowing=10;
extern int Stochastic_Upper=70;
extern int Stochastic_Lower=30;

extern bool Mail_Alert = false;
extern bool PopUp_Alert = false;
extern bool Sound_Alert = false;
extern bool SmartPhone_Notifications=false;

double UsePoint;
int UseSlippage;

double Order_Stop;

datetime TheTime;

int LastKDB;
int LastKDS;

double Order_Profit;

string Order_Type = "BuySell";
double PriceForSecond;

bool BreakEven=false;

int TotalTrades=0;

bool BuysNotAllowed=false;
bool SellsNotAllowed=false;

int Tickets[2] = {0, 0};

int init() {
int i = 0, x;
string info = "";

if (!IsTradeAllowed() || !IsExpertEnabled())
Alert("Trading is not allowed / Expert is not enabled");

UsePoint = PipPoint(Symbol());
UseSlippage = GetSlippage(Symbol(),Slippage);

for(x = 0; x < OrdersTotal(); x++)
if (OrderSelect(x, SELECT_BY_POS, MODE_TRADES))
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
Tickets[i++] = OrderTicket();
info += ", #" + IntegerToString(OrderTicket());
if (OrderType() == OP_BUY) {
Order_Type = "Buy";
if (i == 1) {
PriceForSecond = OrderOpenPrice() - (Pips_To_Trade_2 * UsePoint);
Order_Stop = OrderOpenPrice() - (Stop_Loss_In_Pips * UsePoint);
}
}
else {
Order_Type = "Sell";
if (i == 1) {
PriceForSecond = OrderOpenPrice() + (Pips_To_Trade_2 * UsePoint);
Order_Stop = OrderOpenPrice() + (Stop_Loss_In_Pips * UsePoint);
}
}
}
TotalTrades = i;
Print("Init: Total " + Order_Type + " Trades = " + IntegerToString(TotalTrades) + info);

return(0);
}

int deinit()
{
return(0);
}

int start() {
if (TotalTrades) {
CheckProfit();
Comment(Order_Type + " Trades: " + IntegerToString(TotalTrades));
}
else
Comment("");

if (TotalTrades == 2)
return(0);

if(TheTime<Time[1])
{
if(!BuysNotAllowed && ((Order_Type=="BuySell" && TotalTrades==0) || (Order_Type=="Buy" && TotalTrades==1 && Bid<=PriceForSecond)) && RSIBuyCheck(1)) OpenTrade("Buy");

if(!SellsNotAllowed && ((Order_Type=="BuySell" && TotalTrades==0) || (Order_Type=="Sell" && TotalTrades==1 && Bid>=PriceForSecond)) && RSISellCheck(1)) OpenTrade("Sell");

TheTime=Time[1];
}
return(0);
}

void CheckProfit() {
double Profits=0.0;

for (int x = 0; x < TotalTrades; x++)
if (OrderSelect(Tickets[x], SELECT_BY_TICKET) && OrderCloseTime() == 0)
Profits += OrderProfit();
else if (x == 1) { // second trade closed manually
Tickets[x] = 0;
TotalTrades--;
}

if ((TotalTrades == 1 && Profits >= First_Trade_Profit_In_Dollars) ||
(TotalTrades == 2 && Profits >= Second_Trade_Profit_In_Dollars) ||
(Stop_Loss_In_Pips > 0 && TotalTrades > 0 && Order_Type == "Buy" && Ask <= Order_Stop) ||
(Stop_Loss_In_Pips > 0 && TotalTrades > 0 && Order_Type == "Sell" && Bid >= Order_Stop)) {
Print("Profit is " + DoubleToString(Profits, 2));
CloseAllTrades();
return;
}

if (Break_Even && !BreakEven && Profits >= Break_Even_At_Profit) {
Print("Rollover Finch Break Even Begin");
BreakEven = true;
}
if (Break_Even && BreakEven && Profits <= 0)
CloseAllTrades();

return;
}

void CloseAllTrades() {
int i, TT = TotalTrades, GLE;
string info;

if (!IsConnected()) {
Print("CloseAllTrades(: " + TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS) + " IsConnected() is false");
return;
}
if (IsTradeContextBusy()) {
Print("CloseAllTrades(: " + TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS) + " IsTradeContextBusy() is true");
return;
}

for (int x = 0; x < TT; x++) {
if (OrderSelect(Tickets[x], SELECT_BY_TICKET)) {
if (OrderType() == OP_BUY) {
for (i = 0; i < 10 && !OrderClose(OrderTicket(), OrderLots(), Bid, UseSlippage, clrRed); i++) {
GLE = GetLastError();
info = TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS) + " OrderClose(#" +
IntegerToString(OrderTicket()) + ", " + DoubleToString(OrderLots(), 2) +
", " + DoubleToString(Bid, Digits) + " (Bid), " + IntegerToString(UseSlippage) +
"): " + DescribeError(GLE);
Print(info);
if (GLE && IsFatalTradeError(GLE))
break;
Sleep(3000);
RefreshRates();
}
if (i < 10) {
Tickets[x] = 0;
TotalTrades--;
}
}
else if (OrderType()==OP_SELL) {
for (i = 0; i < 10 && !OrderClose(OrderTicket(), OrderLots(), Ask, UseSlippage, clrGreen); i++) {
GLE = GetLastError();
info = TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS) + " OrderClose(#" +
IntegerToString(OrderTicket()) + ", " + DoubleToString(OrderLots(), 2) +
", " + DoubleToString(Ask, Digits) + " (Ask), " + IntegerToString(UseSlippage) +
"): " + DescribeError(GetLastError());
Print(info);
if (GLE && IsFatalTradeError(GLE))
break;
Sleep(3000);
RefreshRates();
}
if (i < 10) {
Tickets[x] = 0;
TotalTrades--;
}
}
}
}
if (TotalTrades == 0) {
BreakEven = false;
Order_Type = "BuySell";
TheTime = Time[1];
Tickets[0] = 0;
Tickets[1] = 0;
}

return;
}

double PipPoint(string Currency) {
double CalcPoint = 0.0001;
int CalcDigits = (int)MarketInfo(Currency, MODE_DIGITS);

if (CalcDigits == 2 || CalcDigits == 3)
CalcPoint = 0.01;

return CalcPoint;
}

int GetSlippage(string Currency, int SlippagePips) {
int CalcSlippage = SlippagePips * 10;
int CalcDigits = (int)MarketInfo(Currency, MODE_DIGITS);

if (CalcDigits == 2 || CalcDigits == 4)
CalcSlippage = SlippagePips;

return CalcSlippage;
}

void OpenTrade(string Type) {
int i, GLE;
string info;
double TheSpread = MarketInfo(Symbol(), MODE_SPREAD) / 10.0;
double Lots = First_Trade_Lots;

if (!IsConnected()) {
Print("OpenTrade: " + TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS) + " IsConnected() is false");
return;
}
if (IsTradeContextBusy()) {
Print("OpenTrade: " + TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS) + " IsTradeContextBusy() is true");
return;
}

if(Digits==2 || Digits==4)
TheSpread = MarketInfo(Symbol(),MODE_SPREAD);

if (TheSpread > Max_Spread_Pips) {
Print("Spread too large, can't place trade");
return;
}

if (TotalTrades == 1)
Lots = Second_Trade_Lots;

if (Type == "Buy") {
for (i = 0; i < 10 && (Tickets[TotalTrades] = OrderSend(Symbol(), OP_BUY, Lots, Ask, UseSlippage, 0, 0,
"Buy Finch Trade: " + Symbol(), Magic, 0, clrGreen)) == -1; i++) {
GLE = GetLastError();
info = "OpenTrade: " + TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS) + ": Buy OrderSend #"
+ IntegerToString(TotalTrades + 1) + ": " + DescribeError(GLE);
Print(info);
if (GLE && IsFatalTradeError(GLE))
return;
Sleep(3000);
RefreshRates();
}
if (i == 10)
return;

if(GetLastError()==4110) {BuysNotAllowed=true;return;}

if (OrderSelect(Tickets[TotalTrades], SELECT_BY_TICKET)) {
if (Stop_Loss_In_Pips > 0 && TotalTrades == 0)
Order_Stop = OrderOpenPrice() - (Stop_Loss_In_Pips * UsePoint);
PriceForSecond = OrderOpenPrice() - (Pips_To_Trade_2 * UsePoint);
}

TotalTrades++;
Order_Type="Buy";

SendAlert("New Trifecta Rollover Finch Buy Trade on the "+Symbol());
}
else if (Type == "Sell") {
for (i = 0; i < 10 && (Tickets[TotalTrades] = OrderSend(Symbol(), OP_SELL, Lots, Bid, UseSlippage, 0, 0,
"Sell Finch Trade: "+Symbol(), Magic, 0, clrRed)) == -1; i++) {
GLE = GetLastError();
info = "OpenTrade: " + TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS) + ": Sell OrderSend #"
+ IntegerToString(TotalTrades + 1) + ": " + DescribeError(GLE);
Print(info);
if (GLE && IsFatalTradeError(GLE))
return;
Sleep(3000);
RefreshRates();
}
if (i == 10)
return;

if(GetLastError()==4111) {SellsNotAllowed=true;return;}

if (OrderSelect(Tickets[TotalTrades], SELECT_BY_TICKET)) {
if (Stop_Loss_In_Pips > 0 && TotalTrades == 0)
Order_Stop = OrderOpenPrice() + (Stop_Loss_In_Pips * UsePoint);
PriceForSecond = OrderOpenPrice() + (Pips_To_Trade_2 * UsePoint);
}

TotalTrades++;
Order_Type="Sell";

SendAlert("New Trifecta Rollover Finch Sell Trade on the "+Symbol());
}
return;
}

bool RSISellCheck(int Loc)
{
double RSIMain = iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,Loc);
if(RSIMain < 50) return(false);
for(int x=Loc;x<=Loc+2;x++)
{
if(High[x]>High[Loc])return(false);
}
for(int y=Loc+4;y<(Loc+CandlesBack);y++)
{
if(High[y]>High[Loc]) break;
int s=y;
for(int z=y-2;z<=y+2;z++)
{
if(High[z]>High[y]){y++; break;}
}
if(s!=y){y--; continue;}
bool OB=false;
for(int k=Loc;k<=y;k++)
{
double RSIOB = iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,k);
if(RSIOB>70) {OB=true; break;}
}
if(OB==false) continue;
double Mom1=iMomentum(Symbol(),0,MomentumPeriod,PRICE_CLOSE,Loc);
double Mom2=iMomentum(Symbol(),0,MomentumPeriod,PRICE_CLOSE,y);
if(Mom1>Mom2) continue;
LastKDS=y;
return(true);
}
return(false);
}
bool RSIBuyCheck(int Loc)
{
double RSIMain = iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,Loc);
if(RSIMain > 50) return(false);
for(int x=Loc;x<=Loc+2;x++)
{
if(Low[x]<Low[Loc])return(false);
}
for(int y=Loc+4;y<(Loc+CandlesBack);y++)
{
if(Low[y]<Low[Loc]) break;
int s=y;
for(int z=y-2;z<=y+2;z++)
{
if(Low[z]<Low[y]){y++; break;}
}
if(s!=y){y--; continue;}
bool OB=false;
for(int k=Loc;k<=y;k++)
{
double RSIOB = iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,k);
if(RSIOB<30) {OB=true; break;}
}
if(OB==false) continue;
double Mom1=iMomentum(Symbol(),0,MomentumPeriod,PRICE_CLOSE,Loc);
double Mom2=iMomentum(Symbol(),0,MomentumPeriod,PRICE_CLOSE,y);
if(Mom1<Mom2) continue;
LastKDB=y;
return(true);
}
return(false);
}
void SendAlert(string Message)
{
if(Mail_Alert) SendMail("New Rollover Finch Alert",Message);
if(PopUp_Alert) Alert(Message);
if(Sound_Alert) PlaySound("alert.wav");
if(SmartPhone_Notifications) SendNotification(Message);
return;
}

string DescribeError(int ErrorNum) {
return IntegerToString(ErrorNum) + "-" + ErrorDescription(ErrorNum);
}

bool IsFatalTradeError(int GLE) {
return GLE == ERR_INVALID_TRADE_PARAMETERS ||
GLE == ERR_NO_CONNECTION ||
GLE == ERR_MALFUNCTIONAL_TRADE ||
GLE == ERR_TRADE_TIMEOUT ||
GLE == ERR_INVALID_STOPS ||
GLE == ERR_TRADE_DISABLED ||
GLE == ERR_NOT_ENOUGH_MONEY ||
GLE == ERR_TRADE_NOT_ALLOWED ||
GLE == ERR_LONGS_NOT_ALLOWED ||
GLE == ERR_SHORTS_NOT_ALLOWED;
}

Top
#464784 - 03/12/17 15:03 Re: Z System result sharing? [Re: RTG]
Sphin Offline
Senior Member

Registered: 12/11/13
Posts: 373
Loc: Fuerth, DE
Happy coding! laugh

Top
#464793 - 03/13/17 03:34 Re: Z System result sharing? [Re: Sphin]
RTG Offline
Member

Registered: 02/23/14
Posts: 159
Going through the code, it does seems overly complex compared to zorro's built in functions.

Top
Page 5 of 5 < 1 2 3 4 5



Gamestudio download | chip programmers | Zorro platform | shop | resources | magazine | manual | support faq | bugs | beta features

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) 3dgamestudio.net