Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 871

 

What am I doing wrong? On m5 it switches fine, but not further

extern string helper111="Настройки Helper";//Helper
extern bool helperTRUE=TRUE;        //Вкл/Выкл Helper
extern bool timeM1=TRUE;            //Переключения на М старт когда ордера все закрыты
extern int helper_period=PERIOD_M5; //Периуд М старт в минутах
extern int helper_period0=PERIOD_H1;//Базовый таймфрейм работы советника
extern int order_period1=6;         //Колво ордеров для переключения на Time 1
extern int helper_period1=PERIOD_D1;//Time 1 в минутах
extern int order_period2=8;         //Колво ордеров для переключения на Time 2
extern int helper_period2=PERIOD_W1;//Time 2 в минутах


int helperrr()
{
   if(helperTRUE==TRUE) {  
   if(timeM1==TRUE && NumberOfPositions()==0) ChartSetSymbolPeriod(0, NULL, helper_period);
   else {
   if(((NumberOfPositions1()>=0 && NumberOfPositions1()<order_period1)
   || (NumberOfPositions1()>=0 && NumberOfPositions2()<order_period1)
   || (NumberOfPositions1()>=0 && NumberOfPositions3()<order_period1)) && _Period != helper_period0)
   ChartSetSymbolPeriod(0, NULL, helper_period0);
   if((NumberOfPositions1()>=order_period1 && NumberOfPositions1()<order_period2 && OrderMagicNumber()==MagicNumber_1)
   || (NumberOfPositions2()>=order_period1 && NumberOfPositions2()<order_period2 && OrderMagicNumber()==MagicNumber_2)
   || (NumberOfPositions3()>=order_period1 && NumberOfPositions3()<order_period2 && OrderMagicNumber()==MagicNumber_3))
   ChartSetSymbolPeriod(0, NULL, helper_period1);
   if((NumberOfPositions1()>=order_period2 && OrderMagicNumber()==MagicNumber_1)
   || (NumberOfPositions2()>=order_period2 && OrderMagicNumber()==MagicNumber_2)
   || (NumberOfPositions3()>=order_period2 && OrderMagicNumber()==MagicNumber_3))
   ChartSetSymbolPeriod(0, NULL, helper_period2);
   }
   }
   return(0);
}
 
fxsaber:

I have not found any trading tools like the dollar index, etc. (indicators?)

they are not allowed to trade on them, how will your code behave?

 
Igor Makanu:

I have not found any trading tools like the dollar index, etc. (indicators?)

trading on them is forbidden, how will your code behave?

Fake OrderSend from an EA does not always allow you to determine its settings.


The code I provided shows the settings of any EA, regardless of symbol properties and others. For example, run an EA of some kind and then this script on the same chart

// Скрипт показывает, в каком режиме Long/Short запущен советник на данном чарте.
void OnStart()
{
  Alert(LongShortToString());
}
 
fxsaber:

Fake OrderSend from an EA does not always reveal its settings.


The code I provided shows the settings of any EA, regardless of symbol properties and others. For example, run an EA of some kind and then this script on the same chart

checked, it works, but

1. in the discussion https://www.mql5.com/ru/forum/214590/page6#comment_11947599

the code should be replaced with return(INIT_SUCCEEDED); - I tried it and did not understand where the EA was missing ))

2. I do not understand why, when I select EA properties and put a different checkbox, the alert does not reappear, when I switch TFs, everything is normal

Библиотеки: Expert
Библиотеки: Expert
  • 2019.04.23
  • www.mql5.com
Expert: Автор: fxsaber...
 
fxsaber:

Fake OrderSend from an EA does not always reveal its settings.


The code I provided shows the settings of any EA, regardless of symbol properties and others. For example, run an EA of some kind and then this script on the same chart

is it possible to add your code to the EA?

int testTicket=OrderSend(Symbol(),OP_SELL,0.01,0,3,0,0,"Sell Try",1,0,CLR_NONE);
if (GetLastError() == 4111) testLONG_SHORT="Long Only Mode"; 
testTicket=OrderSend(Symbol(),OP_BUY,0.01,0,3,0,0,"Buy Try",1,0,CLR_NONE); 
if (GetLastError() == 4110) testLONG_SHORT="Short Only Mode";

With this code it endlessly opens long and short orders on xauusd

 
Lomonosov1991:

Can I add your code to my EA?

Yes.


Forum on trading, automated trading systems & strategy testing

Any MQL4 and MQL5 beginners questions, help and discussion on algorithms and codes

Lomonosov1991, 2019.06.04 19:01

int testTicket=OrderSend(Symbol(),OP_SELL,0.01,0,3,0,0,"Sell Try",1,0,CLR_NONE);
if (GetLastError() == 4111) testLONG_SHORT="Long Only Mode"; 
testTicket=OrderSend(Symbol(),OP_BUY,0.01,0,3,0,0,"Buy Try",1,0,CLR_NONE); 
if (GetLastError() == 4110) testLONG_SHORT="Short Only Mode";

With this code it endlessly opens long and short orders on xauusd

The idea here is that you need exactly zero volumes.
 
fxsaber:

Yes.


The idea here is that you need exactly zero volumes.
It opens 0.01 lots without volume.
int testTicket=OrderSend(Symbol(),OP_SELL,0,0,3,0,0,"Sell Try",1,0,CLR_NONE);
if (GetLastError() == 4111) testLONG_SHORT="Long Only Mode"; 
testTicket=OrderSend(Symbol(),OP_BUY,0,0,3,0,0,"Buy Try",1,0,CLR_NONE); 
if (GetLastError() == 4110) testLONG_SHORT="Short Only Mode";

and that doesn't work at all.

int testTicket=OrderSend(Symbol(),OP_SELL,0,0,0,0,0,"Sell Try",1,0,CLR_NONE);
if (GetLastError() == 4111) testLONG_SHORT="Long Only Mode"; 
testTicket=OrderSend(Symbol(),OP_BUY,0,0,0,0,0,"Buy Try",1,0,CLR_NONE); 
if (GetLastError() == 4110) testLONG_SHORT="Short Only Mode";





 
Igor Makanu:

checked, it works, but

1. in the discussion at https://www.mql5.com/ru/forum/214590/page6#comment_11947599

I should replace the code with return(INIT_SUCCEEDED); - I tried it and did not understand where the Expert Advisor was missing ))

I purposely put FAILED in this example, so that I would not need to remove it manually later.

2. I do not understand why, when I select EA properties and put a different checkbox, the alert does not reappear, when I switch TFs, everything is normal

When changing Long/Short there is no OnDeinit/OnInit call.

 
I don't understand how to run it((
Files:
 
fxsaber:

No OnDeinit/OnInit call when changing Long/Short.

strange behavior, normally OnIniT() is executed after the settings window is called.


Lomonosov1991:
I don't understand how to run it((

attached the sample, unzip it and scatter in folders

Files:
MQL4.zip  5 kb