Hi coders,
please still cannot write the code. I would like to trade range with 50 bars while start time is 9 hour. Break high / low should be in the range from 9hour to 12 hour. If more than 12 hours order does not apply. Code is without errors...but it still does not work according to my ideas.
Need one trade per day (SELL or BUY or nothing).
int h = TimeHour(TimeCurrent());
int ticket, q;
int StartBar = iBarShift(Symbol(), PERIOD_M5, h == 9);
int highest = iHighest(Symbol(), PERIOD_M5, MODE_HIGH, 50, StartBar);
double high = iHigh(Symbol(), PERIOD_M5, highest);
int lowest = iLowest(Symbol(), PERIOD_M5, MODE_LOW, 50, StartBar);
double low = iLow(Symbol(), PERIOD_M5, lowest);
// LIMITER - ONE TRADE PER DAY (from 9-12hour)
for(q = 0; q < OrdersTotal(); q++)
{
if(OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber()==Magic_number)
{
return(0);
}
}
if (q<1)
{
// SELL ORDER from 9 to 12pm //
if(Bid <= low && h>9 && h<12)
{
ticket = OrderSend(Symbol(),OP_SELL,Size,Bid,0,high,Bid-PT,Text,Magic_number,0,Red);
}
// BUY ORDER from 9 to 12pm //
if(Ask >= high && h>9 && h<12)
{
ticket = OrderSend(Symbol(),OP_SELL,Size,Ask,0,low,Ask+PT,Text,Magic_number,0,Red);
}
}
Attached picture for better explain.
Thanks for your advices, answers
I appreciate it.
Good evening.
Best regards
Martin
please still cannot write the code. I would like to trade range with 50 bars while start time is 9 hour. Break high / low should be in the range from 9hour to 12 hour. If more than 12 hours order does not apply. Code is without errors...but it still does not work according to my ideas.
Need one trade per day (SELL or BUY or nothing).
int h = TimeHour(TimeCurrent());
int ticket, q;
int StartBar = iBarShift(Symbol(), PERIOD_M5, h == 9);
int highest = iHighest(Symbol(), PERIOD_M5, MODE_HIGH, 50, StartBar);
double high = iHigh(Symbol(), PERIOD_M5, highest);
int lowest = iLowest(Symbol(), PERIOD_M5, MODE_LOW, 50, StartBar);
double low = iLow(Symbol(), PERIOD_M5, lowest);
// LIMITER - ONE TRADE PER DAY (from 9-12hour)
for(q = 0; q < OrdersTotal(); q++)
{
if(OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber()==Magic_number)
{
return(0);
}
}
if (q<1)
{
// SELL ORDER from 9 to 12pm //
if(Bid <= low && h>9 && h<12)
{
ticket = OrderSend(Symbol(),OP_SELL,Size,Bid,0,high,Bid-PT,Text,Magic_number,0,Red);
}
// BUY ORDER from 9 to 12pm //
if(Ask >= high && h>9 && h<12)
{
ticket = OrderSend(Symbol(),OP_SELL,Size,Ask,0,low,Ask+PT,Text,Magic_number,0,Red);
}
}
Attached picture for better explain.
Thanks for your advices, answers
I appreciate it.
Good evening.
Best regards
Martin