[Archive!] Writing an advisor for free - page 11

 
skylord писал(а) >>

Hello.

I just started to learn MQL, I am trying to write an EA...

I am trying to write an EA based on the sidus v.2 indicator, I want it to open a position in the direction I have specified by the EA, only when a new bar is born, i.e. on the first tick it should check if the signal is on the previous bar, and what kind of order - with a stop and a take. Attach indicator file.

I have no luck finding this signal((.

Help, or at least tell me how to do it ...

An Expert Advisor on Sidus Indicator

maybe this will help you or search will help!

or second wind!

 

Thank you vvavva. I have a good idea, but it skips and makes a lot of left signals, but it is not what I need (

How can I ask someone how to request the state of the indicator buffer on the previous bar from the EA?

if (sigCurrent==1 && sigPrevious==2)
{
ExtMapBuffer4[i-1] = High[i-1]-5*Point;
//ExtMapBuffer3[i] = Ask;
entry=true;
entry_point=Ask;
}
else if (sigCurrent==2 && sigPrevious==1)
{
ExtMapBuffer3[i-1] = Low[i-1]-5*Point;
//ExtMapBuffer4[i] = Bid;
entry=true;
entry_point=Bid;

}
An EA needs a matching condition like this

double Up;
double Down;
int res;

Up=iCustom(NULL, 0, "sidus_v.2", 3, 1);
Down=iCustom(NULL,0, "sidus_v.2",2,1);
//---- sell conditions
if(Down==Low)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",MAGICMA,0,Red);
return;
}
//---- buy conditions
if(Up==High)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,",MAGICMA,0,Blue);
return;
}

But it's wrong!!!

Please advise how to act in this case...

 

Hello.

I'm quietly trading, I'm using 4 induks, resistance support lines, trends, blah, blah, blah... I have broken my eyes on the screen, can you help me insert the sound signal on the arrows (buy, sell) and the same arrows in the history with a dotted line (re-cut by the same)

Files:
zigandzag.mq4  16 kb
 
skylord писал(а) >>

Hello.

I just started to learn MQL, I am trying to write an EA...

I am trying to write an EA based on the sidus v.2 indicator, I want it to open a position in the direction I have specified by the EA, only when a new bar is born, i.e. on the first tick it should check if there is a signal on the previous bar, and what kind of signal. Attach indicator file.

I have no luck finding this signal((.

Help, or at least tell me how to do it ...

Hi, just ran the code with my eyes, sorry I'm a terrible lamer, I could be wrong of course, but does the indicator overdraw? Let's just try to think logically

for(int i=0; i<limit; i++)
   {

count from zero bar to all bars in the history, increase the counter.

ExtMapBuffer1[ i]=iMA(NULL,0, FastEMA,0,MODE_EMA,PRICE_CLOSE, i);
     ExtMapBuffer2[ i]=iMA(NULL,0, SlowEMA,0,MODE_EMA,PRICE_CLOSE, i);
     rsi_sig = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i);

everything is clear here.

pipdiffCurrent=(ExtMapBuffer1[i]-ExtMapBuffer2[i]);

fuck the macdak.

if ( pipdiffCurrent>0 && rsi_sig>50) 
     {
       sigCurrent = 1;  //Up
     }
     else if ( pipdiffCurrent<0 && rsi_sig<50)
     {
       sigCurrent = 2;  //Down

If macdac is greater than zero and RSI is greater than 50, the sig is 1, and if less, it is 2

So far, so good.

if (sigCurrent==1 && sigPrevious==2)
     {

here I don't understand... if both macdak is positive and RSI is greater than 50 and macdak is negative and RSI is less than 50... since there's a condition in the code below

sigPrevious=sigCurrent;

then we can equate them...

and stealing the future is a bad idea...

ExtMapBuffer3[i-1]

No, let's replace it with this one, or rather completely modify it, since we already know the logic:

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//----
extern int       FastEMA=14;
extern int       SlowEMA=21;
extern int       RSIPeriod=17;
//----
double BuyBuffer[], SellBuffer[];
int pre_signal = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
     
//----
      SetIndexBuffer(0, BuyBuffer);
      SetIndexLabel(0, "Buy");
      SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1);
      SetIndexArrow(0, 241);
//----
      SetIndexBuffer(1, SellBuffer);
      SetIndexLabel(1, "Sell");
      SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1);
      SetIndexArrow(1, 242);
//----
      return(0);
  }

int deinit()
  {
      
  }

int start()
  {
  

      int counted_bars = IndicatorCounted();

      
   int limit = Bars - 17;

   if( counted_bars > 17) 
     { 
       limit = Bars - counted_bars; 
     }

      for(int i = limit; i >= 0; i --)
        {
             BuyBuffer[ i] = EMPTY_VALUE;
             SellBuffer[ i] = EMPTY_VALUE;      
             
                
                 double a = iMA(NULL,0, FastEMA,0,MODE_EMA,PRICE_CLOSE, i+1);
                 double s = iMA(NULL,0, SlowEMA,0,MODE_EMA,PRICE_CLOSE, i+1);
                 
                
                
                 double a1 = iMA(NULL,0, FastEMA,0,MODE_EMA,PRICE_CLOSE, i);
                 double s1 = iMA(NULL,0, SlowEMA,0,MODE_EMA,PRICE_CLOSE, i);
                 double d1 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i)-50;
             //----
           if( a< s && a1> s1 && d1>0)
               {
                    BuyBuffer[ i] = Low[ i] - iATR(NULL, 0, 14, i);
                    
               }
             if( a> s && a1< s1 && d1<0)
               {
                    SellBuffer[ i] = High[ i] + iATR(NULL, 0, 14, i);         
                    
               }
        
      
        }
      return(0);
  }

Now look, it's a sad picture. Compare it:

Although I may be wrong of course and the indicator does not re-draw, but forgive me, and maybe you can use the opening price (especially in RSI), but not the closing one, so that the signal appears on the bar, where it should =(

 

Thanks for the concern vtoroe_dyxanie )))) I did not write the indicator, it does not re-draw it according to my observations. I use it from the first tick of the next bar when it has already locked. That's why I need to know what was on the previous bar on the first tick. And why does it steal the future? It seems to me that on a given tick, if there is such a match, it assigns one to sigCurrent and at the end of the variable sigPrevious it assigns the same sigCurrent:

sigPrevious=sigCurrent;

and then on the next tick if sigCurrent is already 2 and the sigPrevious variable naturally fills the buffer with 1:

if (sigCurrent==1 && sigPrevious==2)
{
ExtMapBuffer4[i-1] = High[i-1]-5*Point;
//ExtMapBuffer3[i] = Ask;
entry=true;
entry_point=Ask;
}

And as for this:

ExtMapBuffer3[i-1]

I don't quite understand it myself...

But it seems to work fine, arrows draw on the bar at which the signal appears!

But when I removed -1, a lot of surprises appeared(



 
skylord >> :

Thanks for the concern vtoroe_dyxanie )))) I did not write the indicator, it does not re-draw it according to my observations. I use it from the first tick of the next bar when it has already locked. That's why I need to know what was on the previous bar on the first tick. And why does it steal the future? It seems to me that on a given tick, if there is such a match, it assigns one to sigCurrent and at the end of the variable sigPrevious it assigns the same sigCurrent:

sigPrevious=sigCurrent;

and then on the next tick if sigCurrent is already 2 and the sigPrevious variable naturally fills the buffer with 1:

if (sigCurrent==1 && sigPrevious==2)
{
ExtMapBuffer4[i-1] = High[i-1]-5*Point;
//ExtMapBuffer3[i] = Ask;
entry=true;
entry_point=Ask;
}

And as for this:

ExtMapBuffer3[i-1]

I don't quite understand it myself...

But it seems to work fine, arrows draw on the bar at which the signal appears!

But when I removed -1, there were many surprises(
.



But it has one more side effect. Sometimes, when conditions are fulfilled, it gives a signal but does not draw arrows. But when I put it on a chart again all arrows will go back to their place. Is there any way to make it compile on a chart again or update its buffers again?

 
skylord писал(а) >>

Why does it steal the future? It seems to assign one to sigCurrent on a given tick if there is such a match, and it assigns the same sigCurrent to the sigPrevious variable at the end:

sigPrevious=sigCurrent;

and then on the next tick if sigCurrent is already 2 and the sigPrevious variable naturally fills the buffer with 1:

if (sigCurrent==1 && sigPrevious==2)
{
ExtMapBuffer4[i-1] = High[i-1]-5*Point;
//ExtMapBuffer3[i] = Ask;
entry=true;
entry_point=Ask;
}



Your true, inattentive me...

About: " I use it from the first tick of the next bar when it is already fixed. That's why I need to know on the first tick what was on the previous bar. " And I really wonder if you can't use

double iCustom( .... int shift)

the all-knowing help says that

shift - Index of the value obtained from the indicator buffer (shift relative to the current bar by the specified number of periods back).

I wonder if you can write it this way (I wondered myself)

for (i=0; i<limit;i++){

if (iCustom(NULL, 0, "sidus_v.2", 3, i+1)<0 && iCustom(NULL, 0, "sidus_v.2", 3, i)>0)

....

because ooooopsie Wise forum users will hardly condescend to two nerds, left to improve my skills on their own, for it may come in handy.

 
vtoroe_dyxanie писал(а) >>

True, I am inattentive...

About: "I use it from the first tick of the next bar when it has already locked. That's why I need to know on the first tick what was on the previous bar. " And I really wonder if we can't use

double iCustom( .... int shift)

the all-knowing help says that

shift - Index of the value obtained from the indicator buffer (shift relative to the current bar by the specified number of periods back).

I wonder if you can write it in this way (I wondered myself)

for (i=0; i<limit;i++){

if (iCustom(NULL, 0, "sidus_v.2", 3, 1)<0 && iCustom(NULL, 0, "sidus_v.2", 3, 0)>0)

....

as oooooovery Wise forum participants are unlikely to condescend to the two nubs, left to improve their skills on their own, for it may come in handy.

No can not =(

Crap, then how to solve this problem? Well, since you already brought it up: https://www.mql5.com/ru/forum/117268 we'll keep an eye on it =)

 
vtoroe_dyxanie писал(а) >>

No can do =(

Man, then how do you solve this question? Well, since you've already started a thread: 'How to find out the direction from an EA' we'll keep an eye out =)

>> I'll do some tracking for the company!?)

 
vtoroe_dyxanie писал(а) >>

No can do =(

Man, then how do you solve this question? Well, since you've already started a thread: 'How to know the direction from an EA' we'll keep an eye out =)

>> hey! remember i asked you for help? if it's not difficult, can you tell me more? what you have done for me is what i wrote now (i wanted the indicator to show the closest timeframes in one window) this is what????

Files:
test1.mq4  6 kb