[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 228

 

Please help me to add a stop loss to your EA, I've tried everything, but it does not work.

-----------------------------------------+

//| Order_v_Day.mq4 |

//| Copyright © 2010, forex-grail.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2010, forex-grail.ru"

#property link "forex-grail.ru"



double Lots = 0.01; // lot

extern int H = 0 ; // order placing hour

extern int SL = 0; // Stop Loss in pips.

extern int TP = 20; // TakeProfit in pips.

int Slippage = 2; // slippage

int Magic = 70111; // magic


int ticketsell, ticketbuy;

double bid, ask;

string com = "O&D";




int init()

{

return(0);

}


int deinit()

{


return(0);

}

bool isBullish(int shift, int tf = PERIOD_D1) { return(iClose(NULL, tf, shift) > iOpen(NULL, tf, shift)); }

bool isBearish(int shift, int tf = PERIOD_D1) { return(iClose(NULL, tf, shift) < iOpen(NULL, tf, shift)); }

int start()

{

int TotalNumber = 0;

for(int i=0; i<OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

if (OrderMagicNumber() != Magic || OrderSymbol() != Symbol()) continue;

TotalNumber++;

}

if (TotalNumber == 0)

{

ticketsell = 0;

ticketbuy = 0;

}

if(Hour() == H && Minute() == 5 && TotalNumber == 0) // Order open time

{


if(isBearish(1)) // If a previous candle on D1 is "inter-bearish", then buy

{

RefreshRates();

double ask = NormalizeDouble(MarketInfo(Symbol(),MODE_ASK), Digits);

ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage,0,ask+TP*Point,com,Magic,0,Blue);

}


if (isBullish(1)) // If the previous candle is bullish on D1, then sell

{

RefreshRates();

double bid = NormalizeDouble(MarketInfo(Symbol(),MODE_BID), Digits);

OrderSend(Symbol(),OP_SELL,Lots,bid,Slippage,0,bid-TP*Point,com,Magic,0,Red);

}


}

return(0);

}

 
Zhunko:
Upload the archive. I'll have a look at mine.

EURUSD5.csv file of 44.5 MB, compressed by EURUSD5.rar to 7.7 MB

http://files.mail.ru/E2FN87

 
rosman:

EURUSD5.csv file of 44.5 MB has been resized by EURUSD5.rar to 7.7 MB

http://files.mail.ru/E2FN87

This is CSV!!! It needs to be converted to HST to be visible on the chart. Use the import in the quote archive.
 
leonid553:

Instead of

ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage, 0, ask+TP*Point,com,Magic,0,Blue);

try

ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage,bid-SL* Point, ask+TP*Point,com,Magic,0,Blue);

=======================

And forticketsell, similarly

instead of zero: ask+SL* Point

Changed it so the advisor stopped opening orders :(
 
leonid553:

Instead of

ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage, 0, ask+TP*Point,com,Magic,0,Blue);

try

ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage,bid-SL* Point, ask+TP*Point,com,Magic,0,Blue);

=======================

And forticketsell, similarly

instead of zero: ask+SL* Point

The metal trader log says:2011.10.02 13:34:37 2010.11.23 00:05 Order_v_Day_v_1.0 EURUSD,Daily: invalid stoploss for OrderSend function

 
(nikolai123:
The meta trader writes:2011.10.02 13:34:37 2010.11.23 00:05 Order_v_Day_v_1.0 EURUSD,Daily: invalid stoploss for OrderSend function


In upload

(the predefined variables Ask & Bid are capitalised)

 
leonid553:

On download
It works thank you very much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You're a genius:))))))))))))))))))))))))))))
 
Zhunko:
It's a CSV!!! It needs to be converted to HST to be visible on the chart. Use the import in the quote archive.
import doesn't convert anything and export doesn't export a format like HST
 
rosman:
Import does not convert anything, and export does not export a format such as HST
That's weird. It does for me.
 
Question about writing an EA. Can you advise where to find material on bar analysis from another timeframe? Perhaps there are standard functions? Or maybe there are already templates available so I don't have to write the code all over again?