Coding help - page 259

 

I am trying to achieve the tick by tick back testing of a custom chart. Since I have no experience with it, probably someone could give me a help hand to step forward. Because I am apparently doing something wrong.

I am reading quotes from a CSV file and storing them to a FXT and HST files.

Then I mark the FXT file read only. The trouble is, that the Strategy tester never accepts my FXT file, and stops.

What I have no idea about is, how far consistent must be the FXT and HST files. What I mean - e.g. rangebars chart has uniform gap of 1 point in the HST, while it has moderate gap in the FXT. Could it be a problem?

Files:
clipboard72.png  19 kb
 
Ovo:
I am trying to achieve the tick by tick back testing of a custom chart. Since I have no experience with it, probably someone could give me a help hand to step forward. Because I am apparently doing something wrong.

I am reading quotes from a CSV file and storing them to a FXT and HST files.

Then I mark the FXT file read only. The trouble is, that the Strategy tester never accepts my FXT file, and stops.

What I have no idea about is, how far consistent must be the FXT and HST files. What I mean - e.g. rangebars chart has uniform gap of 1 point in the HST, while it has moderate gap in the FXT. Could it be a problem?

Ovo

That should not be a problem at all (much bigger gaps are made in fxt file when you back test than those 1 points). Is the format of the fxt file appropriate (new)?

 
mladen:
Ovo That should not be a problem at all (much bigger gaps are made in fxt file when you back test than those 1 points). Is the format of the fxt file appropriate (new)?

Thanks, I hoped it was not a problem.

I am not quite sure what the actual format of the FXT is, but the one I have renders candles.

First I found the 401 version in MQL4 site, which helped me to reverse-engineer the 405, then I found the CSV2FXT script with the 405 version inside, but I did not fully analyse it yet.

I think the bug sits rather in the header content, which I did not pay much attention to.

So now I should focus rather on FXT header than the candle shape (it renders quite appropriate).

I currently use this structure for the FXT:

struct Shortdate {

int date;

};

struct Padding {

char padding;

};

struct MT4FxtCandle {

datetime openTime;

double open;

double high;

double low;

double close;

uint volume;

uint spread;

Shortdate tickTime;

int flag;

};

struct MT4FxtHeader {

int version;

char copyright[64];

char server[128];

char symbol[12];

int period;

TestModelEnum model;

int bars;

Shortdate fromdate;

Shortdate todate;

Padding p1[4];

double modelquality;

char currency[12];

int spread;

int digits;

Padding p2[4];

double point;

int lot_min;

int lot_max;

int lot_step;

int stops_level;

int gtc_pendings;

Padding p3[4];

double contract_size;

double tick_value;

double tick_size;

ProfitCalcModeEnum profit_mode;

int swap_enable;

int swap_type;

Padding p4[4];

double swap_long;

double swap_short;

int swap_rollover3days;

int leverage;

FreeMarginCalcModeEnum free_margin_mode;

MarginCalcModeEnum margin_mode;

int margin_stopout;

ENUM_ACCOUNT_STOPOUT_MODE margin_stopout_mode;

double margin_initial;

double margin_maintenance;

double margin_hedged;

double margin_divider;

char margin_currency[12];

Padding p5[4];

double comm_base;

int comm_type;

int comm_lots;

int from_bar;

int to_bar;

int start_period[6];

int from;

int to;

int freeze_level;

int reserved[61];

};

 
Ovo:
Thanks, I hoped it was not a problem.

I am not quite sure what the actual format of the FXT is, but the one I have renders candles.

First I found the 401 version in MQL4 site, which helped me to reverse-engineer the 405, then I found the CSV2FXT script with the 405 version inside, but I did not fully analyse it yet.

I think the bug sits rather in the header content, which I did not pay much attention to.

So now I should focus rather on FXT header than the candle shape (it renders quite appropriate).

I currently use this structure for the FXT:

struct Shortdate {

int date;

};

struct Padding {

char padding;

};

struct MT4FxtCandle {

datetime openTime;

double open;

double high;

double low;

double close;

uint volume;

uint spread;

Shortdate tickTime;

int flag;

};

struct MT4FxtHeader {

int version;

char copyright[64];

char server[128];

char symbol[12];

int period;

TestModelEnum model;

int bars;

Shortdate fromdate;

Shortdate todate;

Padding p1[4];

double modelquality;

char currency[12];

int spread;

int digits;

Padding p2[4];

double point;

int lot_min;

int lot_max;

int lot_step;

int stops_level;

int gtc_pendings;

Padding p3[4];

double contract_size;

double tick_value;

double tick_size;

ProfitCalcModeEnum profit_mode;

int swap_enable;

int swap_type;

Padding p4[4];

double swap_long;

double swap_short;

int swap_rollover3days;

int leverage;

FreeMarginCalcModeEnum free_margin_mode;

MarginCalcModeEnum margin_mode;

int margin_stopout;

ENUM_ACCOUNT_STOPOUT_MODE margin_stopout_mode;

double margin_initial;

double margin_maintenance;

double margin_hedged;

double margin_divider;

char margin_currency[12];

Padding p5[4];

double comm_base;

int comm_type;

int comm_lots;

int from_bar;

int to_bar;

int start_period[6];

int from;

int to;

int freeze_level;

int reserved[61];

};

Will try to find some more information too

Some details about the headers of hst and fxt files they never released so I am not sure that we can decipher the format of the header 100% exactly

 

Hello I do not use round numbers but my own personal special numbers and I will like to REPLACE them on the attached indy. My numbers are 5, 15, 31, 45 and 67. Waiting for your kind responds soon

 

OrderModify Error1

Hi all,

I wonder if someone could help me. I don't get any compile error, but while

back testing I get a "OrderModify Error1" from MT4. What could I do better

in my code below?

bool ModifyOrder(int nOrderType,int ord_ticket,double op,double price,double tp,color mColor=CLR_NONE)

{

int cnt,err;

double myStop;

myStop=ValidStopLoss(nOrderType,price);

cnt=0;

while(cnt<totalTries)

{

if(OrderModify(ord_ticket,op,myStop,tp,0,mColor))

{

return(true);

}

else

{

err=GetLastError();

if(err>1) Print(cnt," Error modifying order : (",ord_ticket,") "+ErrorDescription(err)," err ",err);

if(err>0) cnt++;

Sleep(retryDelay);

}

}

return(false);

}

[/CODE]

void OpenBuyOrder()

{

int ticket;

int err,digits;

double myStopLoss=0,myTakeProfit=0,myPrice=0;

myPrice=MarketInfo(Symbol(),MODE_ASK);

myStopLoss=0;

if(StopLoss>0) myStopLoss=myPrice-StopLoss*point;

if(myStopLoss!=0) ValidStopLoss(OP_BUY,myStopLoss);

myTakeProfit=0;

if(UseTakeProfit && TakeProfit>0) myTakeProfit=myPrice+TakeProfit*point;

// Normalize all price / stoploss / takeprofit to the proper # of digits.

digits=MarketInfo(Symbol(),MODE_DIGITS);

if(digits>0)

{

myPrice=NormalizeDouble(myPrice,digits);

myStopLoss=NormalizeDouble(myStopLoss,digits);

myTakeProfit=NormalizeDouble(myTakeProfit,digits);

}

ticket=OrderSend(Symbol(),OP_BUY,lotMM,myPrice,Slippage,myStopLoss,myTakeProfit,setup,MagicNumber,0,LimeGreen);

if(ticket>0 && ModifyOrder(OP_BUY,ticket,OrderOpenPrice(),myStopLoss,myTakeProfit,CLR_NONE))

{

if(Debug) Print("BUY order opened : ",OrderOpenPrice());

}

else

{

err=GetLastError();

Print("Error opening BUY order : ("+err+") "+ErrorDescription(err));

}

}

[/CODE]

[CODE]

void OpenSellOrder()

{

int ticket;

int err,digits;

double myStopLoss=0,myTakeProfit=0,myPrice=0;

myPrice=MarketInfo(Symbol(),MODE_BID);

myStopLoss=0;

if(StopLoss>0) myStopLoss=myPrice+StopLoss*point;

if(myStopLoss!=0) ValidStopLoss(OP_SELL,myStopLoss);

myTakeProfit=0;

if(UseTakeProfit && TakeProfit>0) myTakeProfit=myPrice-TakeProfit*point;

// Normalize all price / stoploss / takeprofit to the proper # of digits.

digits=MarketInfo(Symbol(),MODE_DIGITS);

if(digits>0)

{

myPrice=NormalizeDouble(myPrice,digits);

myStopLoss=NormalizeDouble(myStopLoss,digits);

myTakeProfit=NormalizeDouble(myTakeProfit,digits);

}

ticket=OrderSend(Symbol(),OP_SELL,lotMM,myPrice,Slippage,myStopLoss,myTakeProfit,setup,MagicNumber,0,Red);

if(ticket>0 && ModifyOrder(OP_SELL,ticket,OrderOpenPrice(),myStopLoss,myTakeProfit,CLR_NONE))

{

if(Debug) Print("SELL order opened : ",OrderOpenPrice());

}

else

{

err=GetLastError();

Print("Error opening SELL order : ("+err+") "+ErrorDescription(err));

}

return(0);

}

[CODE]

int HandleTrailingStop(int type,int ticket,double op,double os,double tp)

{

double pt,TS=0,myAsk,myBid;

switch(type)

{

case OP_BUY:

{

myBid=MarketInfo(Symbol(),MODE_BID);

switch(TrailingStopType)

{

case 1: pt=point*StopLoss;

if(myBid-os>pt)

ModifyOrder(type,ticket,op,myBid-pt,tp,Aqua);

break;

case 2: pt=point*TrailingStop;

if(myBid-op>pt && os<myBid-pt)

ModifyOrder(type,ticket,op,myBid-pt,tp,Aqua);

break;

}

return(0);

break;

}

case OP_SELL:

{

myAsk=MarketInfo(Symbol(),MODE_ASK);

switch(TrailingStopType)

{

case 1: pt=point*StopLoss;

if(os-myAsk>pt)

ModifyOrder(type,ticket,op,myAsk+pt,tp,Aqua);

break;

case 2: pt=point*TrailingStop;

if(op-myAsk>pt && os>myAsk+pt)

ModifyOrder(type,ticket,op,myAsk+pt,tp,Aqua);

break;

}

}

return(0);

}

}

Thank you in advance!

 
tfi_markets:
OrderModify Error1

Hi all,

I wonder if someone could help me. I don't get any compile error, but while

back testing I get a "OrderModify Error1" from MT4. What could I do better

in my code below?

bool ModifyOrder(int nOrderType,int ord_ticket,double op,double price,double tp,color mColor=CLR_NONE)

{

int cnt,err;

double myStop;

myStop=ValidStopLoss(nOrderType,price);

cnt=0;

while(cnt<totalTries)

{

if(OrderModify(ord_ticket,op,myStop,tp,0,mColor))

{

return(true);

}

else

{

err=GetLastError();

if(err>1) Print(cnt," Error modifying order : (",ord_ticket,") "+ErrorDescription(err)," err ",err);

if(err>0) cnt++;

Sleep(retryDelay);

}

}

return(false);

}

[/CODE]

void OpenBuyOrder()

{

int ticket;

int err,digits;

double myStopLoss=0,myTakeProfit=0,myPrice=0;

myPrice=MarketInfo(Symbol(),MODE_ASK);

myStopLoss=0;

if(StopLoss>0) myStopLoss=myPrice-StopLoss*point;

if(myStopLoss!=0) ValidStopLoss(OP_BUY,myStopLoss);

myTakeProfit=0;

if(UseTakeProfit && TakeProfit>0) myTakeProfit=myPrice+TakeProfit*point;

// Normalize all price / stoploss / takeprofit to the proper # of digits.

digits=MarketInfo(Symbol(),MODE_DIGITS);

if(digits>0)

{

myPrice=NormalizeDouble(myPrice,digits);

myStopLoss=NormalizeDouble(myStopLoss,digits);

myTakeProfit=NormalizeDouble(myTakeProfit,digits);

}

ticket=OrderSend(Symbol(),OP_BUY,lotMM,myPrice,Slippage,myStopLoss,myTakeProfit,setup,MagicNumber,0,LimeGreen);

if(ticket>0 && ModifyOrder(OP_BUY,ticket,OrderOpenPrice(),myStopLoss,myTakeProfit,CLR_NONE))

{

if(Debug) Print("BUY order opened : ",OrderOpenPrice());

}

else

{

err=GetLastError();

Print("Error opening BUY order : ("+err+") "+ErrorDescription(err));

}

}

[/CODE]

[CODE]

void OpenSellOrder()

{

int ticket;

int err,digits;

double myStopLoss=0,myTakeProfit=0,myPrice=0;

myPrice=MarketInfo(Symbol(),MODE_BID);

myStopLoss=0;

if(StopLoss>0) myStopLoss=myPrice+StopLoss*point;

if(myStopLoss!=0) ValidStopLoss(OP_SELL,myStopLoss);

myTakeProfit=0;

if(UseTakeProfit && TakeProfit>0) myTakeProfit=myPrice-TakeProfit*point;

// Normalize all price / stoploss / takeprofit to the proper # of digits.

digits=MarketInfo(Symbol(),MODE_DIGITS);

if(digits>0)

{

myPrice=NormalizeDouble(myPrice,digits);

myStopLoss=NormalizeDouble(myStopLoss,digits);

myTakeProfit=NormalizeDouble(myTakeProfit,digits);

}

ticket=OrderSend(Symbol(),OP_SELL,lotMM,myPrice,Slippage,myStopLoss,myTakeProfit,setup,MagicNumber,0,Red);

if(ticket>0 && ModifyOrder(OP_SELL,ticket,OrderOpenPrice(),myStopLoss,myTakeProfit,CLR_NONE))

{

if(Debug) Print("SELL order opened : ",OrderOpenPrice());

}

else

{

err=GetLastError();

Print("Error opening SELL order : ("+err+") "+ErrorDescription(err));

}

return(0);

}

[CODE]

int HandleTrailingStop(int type,int ticket,double op,double os,double tp)

{

double pt,TS=0,myAsk,myBid;

switch(type)

{

case OP_BUY:

{

myBid=MarketInfo(Symbol(),MODE_BID);

switch(TrailingStopType)

{

case 1: pt=point*StopLoss;

if(myBid-os>pt)

ModifyOrder(type,ticket,op,myBid-pt,tp,Aqua);

break;

case 2: pt=point*TrailingStop;

if(myBid-op>pt && os<myBid-pt)

ModifyOrder(type,ticket,op,myBid-pt,tp,Aqua);

break;

}

return(0);

break;

}

case OP_SELL:

{

myAsk=MarketInfo(Symbol(),MODE_ASK);

switch(TrailingStopType)

{

case 1: pt=point*StopLoss;

if(os-myAsk>pt)

ModifyOrder(type,ticket,op,myAsk+pt,tp,Aqua);

break;

case 2: pt=point*TrailingStop;

if(op-myAsk>pt && os>myAsk+pt)

ModifyOrder(type,ticket,op,myAsk+pt,tp,Aqua);

break;

}

}

return(0);

}

}

Thank you in advance!

tfi_markets

Error 1 is not an error, it simply means that the modification that you are intending to do would not result in order modification (order would stay the same). You can leave it as is or simply check if the intended changed part is dferent than the value you are going to assign to it

 

Hi, I need help to get the number of days since the beginning tf a renko chart .

Thanks for help

 
lambic:
Hi, I need help to get the number of days since the beginning tf a renko chart . Thanks for help

If you mean since the first (oldest) bar of renko, simply do the following :

int numOfDays = (Time[0]-Time)/(1440*60);

 
mladen:
If you mean since the first (oldest) bar of renko, simply do the following : int numOfDays = (Time[0]-Time)/(1440*60);

So simple ! I was looking for an array function and it was simply Time[]. Sorry it's stupid. Thanks a lot !