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

 

Can you make a robot to open both ways with small stops with lots and choose a winning position? Or is it a fantasy?

 

OK with colour...

The question is - I want to "hide SL" from DC, i.e. not to set it with opening operator, but to assign it to variable inside expert:

extern double TrailingStop=25.0;

extern double Lots=0.1;

....
double StopB;

.....

if( entry condition) {

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0, "Buy EA",123,0,Green);
StopB=Ask-TrailingStop*Lots; //hide
the stop < - am I doing it right?

}

.....

if( profit exit conditions || Ask > StopB)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); //
close position
return(0); // exit
}

And where do we write the SL exit condition? Together with profit closing condition using "||" or separately?

 

Good day! Please advise how to use iCustom function correctly, I want to create conditions for trades by the indicator colour, which is drawn in a separate histogram window:

color Oct_1=iCustom(NULL,0, "octava_1");

if ( Oct_1==Green).... etc.

When compiling the program gives an error, says "'green' - variable not defined, what's the reason?

I'd be very grateful for an answer)))

 

Question removed, the capital letter has a meaning))))

 
DOCTORS:

OK with the colour...

The question is - I want to "hide SL" from brokerage companies, i.e. I don't want to set them with opening operator, but assign them to variable inside of expert:

extern double TrailingStop=25.0;

extern double Lots=0.1;

....
double StopB;

.....

if( entry condition) {

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0, "Buy EA",123,0,Green);
StopB=Ask-TrailingStop*Lots; //hide
the stop < - am I doing it right?

}

.....

if( profit exit conditions || Ask > StopB)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); //
close position
return(0); // exit
}

And where do we write the SL exit condition? Together with profit closing condition using "||" or separately?

I'm not a pro, but I was wondering the same thing. I personally wrote it like this (Professionals will correct me when they come)

This part picks up an open order and assigns stop and take values to variables

// +----------------------------------------------------------------------+
//------- : функция поиска открытых ордеров по символу графика, подхват и установки уровней стопа и профита
double TradeSymbol()
   {
   int    TotalTradeSymbol = 0;
   int    SendGo           = 0;
   total=OrdersTotal();  
   for(cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
        {
        if(OrderType()== OP_BUY)
          {
          if(StopLoss   > 0 && Bid < OrderOpenPrice()) {sl = NormalizeDouble(OrderOpenPrice() - StopLoss*Point, Digits);}  
          if(TakeProfit > 0)                           {tp = NormalizeDouble(OrderOpenPrice() + TakeProfit*Point, Digits);}
          }
        if(OrderType()== OP_SELL)
          {
          if(StopLoss   > 0 && Ask > OrderOpenPrice()) {sl = NormalizeDouble(OrderOpenPrice() + StopLoss*Point, Digits);}  
          if(TakeProfit > 0)                           {tp = NormalizeDouble(OrderOpenPrice() - TakeProfit*Point, Digits);} 
          }
        if(OrderStopLoss()   != sl){SendGo++;}
        if(OrderTakeProfit() != tp){SendGo++;}
        if(!UseVirtualTradeLevel && SendGo != 0) {OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,CLR_NONE);}
        TotalTradeSymbol++;
        }
      }
    return(TotalTradeSymbol);  
    }
// +----------------------------------------------------------------------+

this part checks and closes at the take

// +----------------------------------------------------------------------+
//------- : функция проверки тейкпрофита
void CheckTakeProfit()
   {
   if(tp == 0)return(0);
   total=OrdersTotal();  
   for(cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
        {
        if(OrderType()== OP_BUY)
          {
          if(Bid > tp)
            {
            OrderClose(OrderTicket(), OrderLots(), Bid, SleepPage, Lime);
            if(UseSound)PlaySound("ok.wav");
            }
          }
        if(OrderType()== OP_SELL)
          {
          if(Ask < tp)
            {
            OrderClose(OrderTicket(), OrderLots(), Ask, SleepPage, Lime);
            if(UseSound)PlaySound("ok.wav");
            }
          }
        }
      }
    }
// +----------------------------------------------------------------------+

this part checks and closes at stop

// +----------------------------------------------------------------------+
//------- : функция проверки стоплоса
void CheckStopLoss()
   {
   if(sl == 0)return(0);
   total=OrdersTotal();  
   for(cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
        {
        if(OrderType()== OP_BUY)
          {
          if(Bid < sl)
            {
            OrderClose(OrderTicket(), OrderLots(), Bid, SleepPage, Blue);
            if(UseSound)PlaySound("ok.wav");
            }
          }
        if(OrderType()== OP_SELL)
          {
          if(Ask > sl)
            {
            OrderClose(OrderTicket(), OrderLots(), Ask, SleepPage, Blue);
            if(UseSound)PlaySound("ok.wav");
            }
          }
        }
      }
    }
// +----------------------------------------------------------------------+
P.S.

Professionals - don't mock the self-taught, maybe it could be different, but it works for me ....

 
elmucon:

I'm not a pro, but I was wondering the same thing. I personally wrote it this way (if you're a pro - correct me)

This part picks up an open order and assigns stop and take values to variables

this part checks and closes at the take

this part checks and closes at stop

P.S.

Professionals - don't mock the self-taught, maybe it could be different, but it works for me ....

Everything is practically fine! The only thing is that there are a couple of oddities on entry/exit. Well, and such a strategy does not save from slippage. But thanks a lot!
 

How do I determine the current timeframe for the EA?

If the timeframe is M1, I need to fulfil one condition, and if the timeframe is M5, I need to fulfil another condition.

 
sss2019:

How do I determine the current timeframe for the EA?

If the timeframe is M1, I need to fulfil one condition, and if the timeframe is M5, I need to fulfil another condition.


Using the Period() function
 
sss2019:

How do I determine the current timeframe for the EA?

If the timeframe is M1, I need to fulfil one condition, and if the timeframe is M5, I need to fulfil another condition.

if (Period()==1) return; //Условие минуток
if (Period()==5) bool working=true; //Условие пятиминуток
 
splxgf:


Thank you. So period M1 corresponds to value 1, and period M5 corresponds to value 5, so it turns out that period H1 corresponds to 60, and period H4 to 240 right?

I need this construction to work: when period M1 is selected case 1 and when period M15 is selected case 15. Will it work, or is it necessary to do case 1 case 2 case 3 - in order?

  switch(Period())
    {
    case 1 : Ba = 60;
    case 5 : Ba = 12;
    case 15 : Ba = 4;
    case 30 : Ba = 2;
    case 60 : Ba = 1;
    }