[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 57

 
Karabas >> :

Hi, could you tell me if it is possible to change the colour of the indicator? Let's say there are two moving averages with different periods in the main window with different colours. >> Thank you


Right click on one of the MAs (Moving Average) a window will pop up, click on "properties of Moving Average" and there you will see where to change the colour

 
xruss >> :

Cls_B and Cls_S allow to close a position and they cannot contradict Opn_B Opn_S. here you need to write in the code a time-series that would mark the bar where the Buy or Sell order was opened and where it should be closed so that no more positions would open during this period((

I don't mean to replace the opening conditions you already have, but to add new ones to them. As I understand it, you want to prohibit the EA from opening a position on a signal to open, if there is no signal to close on the same signal. So add:

if (Opn_B==true && Cls_B==false) { не открывать Buy }
if (Opn_C==true && Cls_C==false) { не открывать Sell }

And if you do it your way - how do you calculate the bar at which a position should close there sometime? :)

 

Hello

//+------------------------------------------------------------------+
int start()
  {
//----
 double Macd_0=iMACD(NULL,0, MAFastPeriod, MASlowPeriod, MASignalPeriod,1,0,0);
 double Macd_1=iMACD(NULL,0, MAFastPeriod, MASlowPeriod, MASignalPeriod,1,0,1);
 double signal_0=iMACD(NULL,0, MAFastPeriod, MASlowPeriod, MASignalPeriod,1,1,0);
 double signal_1=iMACD(NULL,0, MAFastPeriod, MASlowPeriod, MASignalPeriod,1,1,1);
    
    if(( Macd_0 < Macd_1 && Macd_1 > 0) && ( signal_0 < signal_1 && signal_1 > 0))
     if( CheckOrders(OP_SELL))
      {
       if(!OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, NULL, MagicNumber))
         Print("Не открыт ордер Buy. Ошибка №", GetLastError()); 
       }
       
    if(( Macd_0 > Macd_1 && Macd_1 < 0) && ( signal_0 > signal_1 && signal_1 < 0))
     if( CheckOrders(OP_BUY))
      {
       if(!OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, NULL, MagicNumber))
         Print("Не открыт ордер Sell. Ошибка №", GetLastError()); 
       }

//----
   return(0);
  }
//+------------------------------------------------------------------+

This is the first option.

//+------------------------------------------------------------------+
int start()
  {
//----
 double Macd_0=iMACD(NULL,0, pFast, pSlow, pSignal,1,0,0);
 double Macd_1=iMACD(NULL,0, pFast, pSlow, pSignal,1,0,1);
 double signal_0=iMACD(NULL,0, pFast, pSlow, pSignal,1,1,0);
 double signal_1=iMACD(NULL,0, pFast, pSlow, pSignal,1,1,1);
    
    if(( Macd_0 < Macd_1 && Macd_1 > 0) && ( signal_0 < Macd_0 && signal_1 < Macd_1 && signal_1 > 0))
     if( CheckOrders(OP_SELL)) //продажа
      {
       if(!OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, NULL, MagicNumber))
         Print("Не открыт ордер Buy. Ошибка №", GetLastError()); 
       }
       
    if(( Macd_0 > Macd_1 && Macd_1 < 0) && ( signal_0 > Macd_0&& signal_1 > Macd_1&& signal_1 < 0))
     if( CheckOrders(OP_BUY)) //покупка
      {
       if(!OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, NULL, MagicNumber))
         Print("Не открыт ордер Sell. Ошибка №", GetLastError()); 
       }

//----
   return(0);
  }
//+------------------------------------------------------------------+

This is the second variant.

Expert Advisor based on macd, trading is simple (everything is based on 0 and 1 bar, price is open).

In the first case the macd values increase (for buy), for sell they decrease. Signal line is also based on these conditions.

In the second case I tried to realize crossing of fast and slow macd line. But some doubts remained.............Whether it is correct.........

 
Everlost >> :

I don't mean to replace the opening conditions you already have, but to add new ones to them. As I understand it, you want to prohibit the EA from opening a position on a signal to open, if there is no signal to close on the same signal. So add them:

if (Opn_B==true && Cls_B==false) { не открывать Buy }
if (Opn_C==true && Cls_C==false) { не открывать Sell }

And if you do it your way - how do you calculate the bar at which the position should close at some point? :)

how do I open a position?)

because it opens when Opn_B=true Cls_B=false and Cls_B cannot be true at that moment.


let's say we have a MA` that crossed the price quotes (formed Opn_S), opened a position downwards and SL- moved to Breakeven. and then the price slipped SL to Breakeven and...

in my case, a position is opened down(((( before a new signal of MA` crossing the price (Cls_S) is formed



 
xruss >> :

but how will my position open?:)

because it opens when Opn_B=true Cls_B=false and Cls_B cannot be true at that moment.

Ok, create another variable, for example, int Last_Position=-1. Enter there the order type as soon as the position is opened. And add conditions:

if (Opn_B==true && Last_Position==OP_BUY) { сигнал Buy пропускаем }

 
Everlost >> :

OK, create another variable, e.g. int Last_Position=-1. Enter there the order type as soon as the position is opened. And add conditions:

if (Opn_B==true && Last_Position==OP_BUY) { сигнал Buy пропускаем }

That's more or less how I did it, but I was a bit disappointed in the result(

Sometimes the trend slackens, goes into a flat position (it corrects) and then keeps moving again with a new strength and gives the right Opn_S signal which will be blocked in this way. How to limit the trading by one order in the area from Opn_S to Cls_S signal and from Opn_B to Cls_B?

 
xruss >> :

I did it that way, but I'm not happy with the result((

Sometimes the trend weakens, goes into a flat (makes a correction) and then continues to move with a new strength and gives the right signal Opn_S, which will thus be blocked. How to limit the trade with one order in the area from the signal Opn_S to Cls_S and from Opn_B to Cls_B?

It is very simple - when the signal Cls_S or Cls_B is received, you should forget about the position opened last (reset the value of the variable Last_Position back to -1).

if ((Cls_S==true || Cls_B==true) && Last_Position>=0) Last_Position=-1;

 
Can you advise how to add a condition to the Expert Advisor, so it knows that the previous trade was losing?
 
Dimoncheg >> :
Can you tell how to spell the condition in your EA, so it knows that the previous trade was loss-making?

if (OrderProfit() < 0) {

...

}

 
Dear experts, please don't ignore my question.

Is there an indicator that counts volatility, for example daily. But not the one, that gives an undefined number like 0.34. But it should calculate the number of candlesticks per day and divide it by a given period (number of days) so that the indicator knows the average value. Example: Opening 100, closing 200; the second day - opening 200, closing 250. Average volatility for these 2 days = ((200-100)+(250-200))/2 days=(100+50)/2=75
Where to download if available.