You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi Every One;
I need to write a code to open trade as the following:
I open the trade by end of the candle so I open sell if the close price more than the open price, and I open Buy if the close price less than the open price.
so if I use the one hour chart , and the last price or the close price for the last candle more than the open day price then and the transaction is sell so the size will be the same i use in my expert, but if the transaction was Buy and the close price for the last candle more than the day open price then i need to make it double I use in my expert.
the same thing will be if the close price for the last candle less than the day open price the Buy transaction still the same size I use but the Sell transaction i need to make it double.
but I don't know how can I write or modified the code and here is my code:
extern double Lots = 0.01;
extern int StopLoss = 0 ;
extern int TakeProfit = 0 ;
extern int in_Hour = 04 ;
extern int out_Hour = 20 ;
extern int RunningBarsToExit = 10 ;
extern int Magic = 10;
extern bool CloseAll = false;
//+------------------------------------------------------------------+
//| Static Parameters ãÊÛíÑÇÊ ÚÇãÉ |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Initialization function ÏÇáÉ ÇáÊåíÆÉ æÊäÝÐ ÚäÏ ÇáÏÎæá ááÇßÓÈíÑÊ |
//+------------------------------------------------------------------+
int init()
{
//----
Lots = MathMax(MarketInfo(Symbol(),MODE_MINLOT), Lots);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Deinitialization function ÏÇáÉ ÇáÊÕÝíÉ æÊäÝÐ ÚäÏ ÇáÎÑæÌ ÝÞØ |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Start function ÇáÏÇáÉ ÇáÑÆíÓíÉ æÊäÝÐ ÚäÏ ßá ÊÛíÑ ÈÇáÓÚÑ |
//+------------------------------------------------------------------+
int start(){
if(IsTradeContextBusy()) return 0;
bool PlayTime = Hour()>=in_Hour && Hour()<=out_Hour;
//===== Part 1: Check opened positions:
double curTotal=0, BuyRun=0, SellRun=0;
for (int cnt=0; cnt<OrdersTotal(); cnt++) {
if(!OrderSelect(cnt,SELECT_BY_POS)) continue ;
if(OrderSymbol()!=Symbol()) continue;
if(OrderMagicNumber()!= Magic) continue;
curTotal+=1 ;
if(OrderOpenTime()<iTime(NULL,0,0)) continue;
if (OrderType()==OP_SELL) { SellRun=OrderOpenPrice(); }
if (OrderType()==OP_BUY) { BuyRun =OrderOpenPrice(); }
}
if (curTotal>0 && !PlayTime) CloseAll=true;
if (curTotal==0) CloseAll=false;
if (CloseAll) PerformCloseAll(Magic);
//=======Part 2: Initialize Parms:
bool Long = (BuyRun==0 && PlayTime && (iClose(NULL,0,1)- iOpen(NULL,0,1))< (-0.0002));
bool Short= (SellRun==0 && PlayTime && (iClose(NULL,0,1)- iOpen(NULL,0,1))> ( 0.0002));
double tLot = Lots * MathAbs(iClose(NULL,0,1) - iOpen(NULL,0,1));