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

 

Hello all, I think I have written to the right place. I have a great desire to learn mql4 programming language to start with scripts, then indicators and EAs, in particular, now I have set a task to write an EA myself to trade using one of the tactics. (I have read on the forum they start with scripts.) I am an expert in coding, I know little about Pascal and Delphi and I have studied C ++, I have read mql but I think it is not so different. I need help writing programs right or wrong code optimization, etc.. Who can help?

Thanks in advance!!!

 

Please advise on example, here is a simple code, advisor opens BAY with stop and profit, and puts pending order. What should I write in the code, so that when it reaches a profit, pending order is deleted and everything starts from the beginning..... and when it reaches a stop, for example, Alert ("Stopak").

//+------------------------------------------------------------------+
//| test.mq |
//| Copyright © 2011 |
//| http:// |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double Lot = 0.01;
extern int TakeProfit = 200;
extern int StopLoss = 200;
extern double Step = 0.0020;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialisation function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==false)
{
{ OrderSend(Symbol(),OP_BUY,Lot,Ask,30,Ask-StopLoss*Point,Ask+TakeProfit*Point,0,0,0,Green); }
{ OrderSend(Symbol(),OP_SELLSTOP,Lot,Ask-Step,30,Ask,Ask-Step-TakeProfit*Point,0,0,0,Red); }
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+

 
MIR-ASOV:

Please advise on the example, here is a simple code, the EA opens BAY with a stop and profit, and puts pending order. What do I need to write in the code, so that when you get a profit pending removed and everything started over..... and when you get a stop, for example, was Alert ("Stopak").

//+------------------------------------------------------------------+
//| test.mq |
//| Copyright © 2011 |
//| http:// |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double Lot = 0.01;
extern int TakeProfit = 200;
extern int StopLoss = 200;
extern double Step = 0.0020;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialisation function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==false)
{
{ OrderSend(Symbol(),OP_BUY,Lot,Ask,30,Ask-StopLoss*Point,Ask+TakeProfit*Point,0,0,0,Green); }
{ OrderSend(Symbol(),OP_SELLSTOP,Lot,Ask-Step,30,Ask,Ask-Step-TakeProfit*Point,0,0,0,Red); }
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+

Look in textbooks for an algorithm for accounting for orders. Then connect logic to all this, and the result will be obvious!

Also, work on the code syntax. Lots of curly braces...


frixer:

Hello all, I think I have written to the right place. I have a great desire to learn mql4 programming language to start with scripts, then indicators, and EAs, in particular, now I have set a task to write an EA myself to trade by one of the tactics. (I have read on the forum they start with scripts. I am very unfamiliar with programming, Pascal, Delphi and C++ studies, I have read mql but I think they are not that different. I need some advise how to write programs right or wrong, code optimization, etc. Who can help?

Thanks in advance!!!

So you write here, we can help. Or do you need a home tutor? :)))
 

How to perform such an action in an EA:

All these conditions may not follow one after the other (may be in an hour or two or three), so we have to make it so as soon as the indicator reaches 1.0000, this condition is not checked at every tick anymore, and wait until one bar closes with fall, and after that these 2 conditions are not checked at every tick, and wait until the indicator reaches 0.9980 or equal. As soon as all conditions are fulfilled we open a market order to sell 0.1 lot with a stop loss of 100p and take profit of 400p.

Can anyone help? Maybe someone has a ready example or give me a link?

 
kolyango:

How to perform such an action in an EA:

All these conditions may not follow one after the other (may be after an hour or two or three), so we have to make it so as soon as the indicator reaches 1.0000, this condition is not checked at every tick anymore, and wait until one bar closes with fall, and after that these 2 conditions are not checked at every tick, and wait until the indicator reaches 0.9980 or less. As soon as all conditions are fulfilled we open a market order to sell 0.1 lot with a stop loss of 100p and take profit of 400p.

Can anyone help? Maybe someone has a ready example or give me a link?

When an event occurs, put a Boolean condition and an expiry time.
 
kolyango:

How to perform such an action in an EA:

All these conditions may not follow one after the other (may be in an hour or two or three), so we have to make it so as soon as the indicator reaches 1.0000, this condition is no longer checked at every tick, and wait until one bar closes with fall, and after that these 2 conditions are not checked at every tick, and wait until the indicator reaches 0.9980. Once all conditions are met open a market order to sell 0.1 lot with a stop loss of 100p and take profit of 400p.

Can anyone help? Maybe someone has a ready example or give me a link?


Here's an article to help - look at the analogy there...

In the trailer - the inclusion of the execution of these trading criteria according to this article, written according to the tutorial, see here.

You've got it all in the same way...

Files:
criterion.mqh  12 kb
 
kolyango:

How to perform such an action in an EA:

All these conditions may not follow one after the other (may be in an hour or two or three), so we have to make as soon as the indicator reaches 1.0000, this condition is not checked at every tick anymore, and wait until one bar closes with fall, and after that these 2 conditions are not checked at every tick, and wait until the indicator reaches 0.9980. Once all conditions are fulfilled open a market order to sell 0.1 lot with a stop loss of 100p and take profit of 400p.

Can anyone help? Maybe someone has a ready example or give me a link?

It's as simple as that. Let's use flags as a semaphore. There will be three code blocks, each of which will be executed only if the previous one is already executed.

Initially all flags ==false.

As soon as the first condition is fulfilled, the first flag=true; Now the second code block is executed. As soon as its condition is fulfilled, set second flag=true;
Now the third code block is executed. As soon as its condition is met, set the third flag=true; And so on.

 
artmedia70:

It's as simple as that. Let's use the flags as a semaphore. There will be three blocks of code, each of which will be executed only if the previous one is already executed.

Initially all flags ==false.

As soon as the first one has been executed, we put first flag=true; Now the second code block is executed. As soon as its condition is fulfilled, set second flag=true;
Now the third code block is executed. As soon as its condition is met, set the third flag=true; And so on.



And when to drop the flags he did not write
 

Can you tell me which font the terminal uses? I would like my comments to be the same as the standard ones

if(spread >= 20)
       spreadColor = Red;
  else
       spreadColor = White;
  ObjectSetText("Spread", "Spread " + Symbol() + ": " + DoubleToStr(spread, 0), 8, "Tahoma Bold"/*"Calibri"*/, spreadColor);//"Webdings"
 

Guys, when optimizing on one terminal, I start a test on another terminal and the last terminal crashes with this error...does anyone know what the possible reason is??? Before, when I started this terminal - it asked for an update to version 409, I updated it, it restarted and kept asking for the same update...I - cancelled, closed, then ran it myself...it kept asking for that update.

Haven't checked on the new terminal yet... CPU load is at 100% all the time... Running the test in visualisation mode on the third terminal - it's testing fine...


Reason: