[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 611

 

Help me write a simple indicator that draws lines of highs and lows in the main window for the required period (which is set with an external variable).

 

Please tell me where to find a 15-day weekday planner.

Please give me a link or a file or name.

And as always thank you for your time.

 
41ckm39fi:

Good evening.

Could you please tell me what the error is, the indicator does not give a message about crossing two MAs.


Did you think carefully before writing this indicator?

Please explain the logic, at least for yourself.

#property indicator_chart_window

extern int        Period_MA_fast         = 5,
                  Period_MA_med          = 8,
                  Period_MA_slow         = 16,
                  period_DeMarker       = 14;
//---- 
double            DeMarker_buffer0[],
                  Speed_MA_fast[],
                  Speed_MA_med[],
                  Speed_MA_slow[];      

#define SIGNAL_BAR 1
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- indicators
   IndicatorBuffers(4);
   SetIndexBuffer(0,DeMarker_buffer0);
   SetIndexBuffer(1,Speed_MA_fast);
   SetIndexBuffer(2,Speed_MA_med);
   SetIndexBuffer(3,Speed_MA_slow);
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexStyle(2,DRAW_NONE);
   SetIndexStyle(3,DRAW_NONE);
   //----
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int    counted_bars=IndicatorCounted();
   int    i,limit;
   
   if(counted_bars>0) counted_bars--;
      limit=Bars-counted_bars;
   //----
   for(i=limit; i>=0; i--) {
      DeMarker_buffer0[i]=iDeMarker(NULL,0,14,i);
      Speed_MA_med[i]=iMA(NULL,0,Period_MA_med,0,MODE_LWMA,PRICE_CLOSE,i);
      Speed_MA_slow[i]=iMA(NULL,0,Period_MA_slow,0,MODE_LWMA,PRICE_CLOSE,i);
   }
   
   for(i=limit; i>=0; i--)
      Speed_MA_fast[i]=iMAOnArray(DeMarker_buffer0,0,5,0,MODE_LWMA,i);
   
   static int PrevTime = 0;

   if(PrevTime >= Time[0] ) return(0);
   PrevTime = Time[0];

   if(Speed_MA_fast[SIGNAL_BAR] - 0.3 > 0)
      if (0.3 - Speed_MA_fast[SIGNAL_BAR+1] >= 0)
         Alert( "sMA(", Symbol(), ", ", Period(), ")  -  BUY!!!" );

   if(0.7 - Speed_MA_fast[SIGNAL_BAR] > 0)
      if (Speed_MA_fast[SIGNAL_BAR+1] - 0.7 >= 0)
         Alert("sMA(", Symbol(), ", ", Period(), ")  -  SELL!!!");

   if(Speed_MA_med[SIGNAL_BAR] - Speed_MA_slow[SIGNAL_BAR] > 0)
      if (Speed_MA_med[SIGNAL_BAR+1] - Speed_MA_slow[SIGNAL_BAR+1] >= 0)  
         Alert( "speedMA(", Symbol(), ", ", Period(), ")  -  BUY!!!" );   

   if(Speed_MA_slow[SIGNAL_BAR] - Speed_MA_med[SIGNAL_BAR] > 0)
      if (Speed_MA_slow[SIGNAL_BAR+1] - Speed_MA_med[SIGNAL_BAR+1] >= 0)  
         Alert( "speedMA(", Symbol(), ", ", Period(), ")  -  SELL!!!" );     
  
  
   return(0);
}
//+------------------------------------------------------------------+
It might work, haven't tested it
 

Thank you all! There is one more question.........

i have an EA with entry and exit conditions based on certain signals(no matter what)

i.e. three screens-one indicator, for example Force or Stohostick

exit conditions also only by it -

everything is OK, but an additional Stop Loss is needed to protect the positions

i.e. =10p.

................. can i use this EA without additional Losses, at least

it may be possible to use such an Expert Advisor without additional Losses at least at small lots=0.01 because the exit signal will anyway

P.S. I was thinking email or ICQ-just opened and MT messaged you

and you're thinking about where your best stop would be.

....... don't say no to anyone who asks you.

 
KlugerX35:

Thank you all! There is one more question.........

i have an EA with entry and exit conditions based on certain signals(no matter what)

i.e. three screens-one indicator, for example Force or Stohostick

exit conditions also only by it -

everything is OK, but an additional Stop Loss is needed to protect the positions

i.e. =10p.

................. can i use this EA without additional Losses, at least

it may be possible to use such an Expert Advisor without additional Losses at least at small lots=0.01 because the exit signal will anyway

P.S. I was thinking email or ICQ-just opened and MT messaged you

and you're thinking about where your best stop would be.

....... don't say no to anyone who asks you.


If the Expert Advisor has a "technical" exit, it does not need a stop, if you want to put a stop just in case, for insurance, then put a bigger one.

10p is a real loss.

For what period is it so small, for a minute? Of course it's haywire, and will chop even potentially profitable trades.

Is it possible to use such an Expert Advisor without additional LOS, at least

just use a small lot=0.01

If it works stably, handles errors normally, and you are satisfied with the trading results, then you can.
 

This is a question - can someone please explain.

Why does it say that closing by counter-order saves one spread? After all the first deal, for example Buy is bought at Ask and sold at Bid price at that time (there is no profit in total position size), and the second deal - Sell is opened at Bid and correspondingly the position length is calculated based on Ask close price.

The manual gives some unclear example https://book.mql4.com/ru/trading/orderclose where the difference is not in the spread as stated, but in the size of the second deal - in a 2-for-15 closure of one deal, and the opposite one - only 15, i.e. all the losses of the deal disappear, but not the spread.

So what's the catch here?

 
FatyM:

Please tell me where to find a 15-day weekday planner.

Please give me a link or a file or name.

And as always thank you for your time.

Files:
 
Vinin:


Did you think carefully before writing this indicator?

Write down the logic, at least for yourself.

Maybe it will work, I haven't checked

I rewrote the logic of muwings comparison still no messages, I can't figure out what the error is.
#property indicator_chart_window
#property  indicator_level1 0.3
#property  indicator_level2 0.7
//---- 
extern int        Period_DeMarker       = 14;
//---- 
double            DeMarker_buffer0[],
                  MA0[],
                  MA1[],
                  MA11[],
                  MA2[],                        
                  MA22[];      

#define SIGNAL_BAR 1
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
IndicatorBuffers(6);
SetIndexBuffer(0,DeMarker_buffer0);
SetIndexBuffer(1,MA0);
SetIndexBuffer(2,MA1);
SetIndexBuffer(3,MA2);
SetIndexBuffer(4,MA11);
SetIndexBuffer(5,MA22);
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_NONE);
SetIndexStyle(2,DRAW_NONE);
SetIndexStyle(3,DRAW_NONE);
SetIndexStyle(4,DRAW_NONE);
SetIndexStyle(5,DRAW_NONE);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int    i,limit;
//----
if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//----
  for(i=limit; i>=0; i--)
  DeMarker_buffer0[i]=iDeMarker(NULL,0,14,i);
//---- 
  for(i=limit; i>=0; i--)
  
  MA0[i]=iMAOnArray(DeMarker_buffer0,0,5,0,MODE_LWMA,i);
//----   
  static int PrevTime = 0;
//---- 
  if(PrevTime >= Time[0]) return(0);
//---- 
  PrevTime = Time[0];
//----
                if(MA0[SIGNAL_BAR] - 0.3 > 0 && 0.3 - MA0[SIGNAL_BAR+1] >= 0)  
//---- 
                                Alert( "sMA(", Symbol(), ", ", Period(), ")  -  BUY!!!" );
//----
if(PrevTime <= Time[0]) 

return(0);
//---- 
  PrevTime = Time[0];
//----          
                if(0.7 - MA0[SIGNAL_BAR] > 0 && MA0[SIGNAL_BAR+1] - 0.7 >= 0)
//----               
                                Alert("sMA(", Symbol(), ", ", Period(), ")  -  SELL!!!");
                                
                                
MA1[i]=iMA(NULL,0,8,0,MODE_LWMA,PRICE_CLOSE,i);
                        
MA2[i]=iMA(NULL,0,16,0,MODE_LWMA,PRICE_CLOSE,i);

MA11[i]=iMA(NULL,0,8,0,MODE_LWMA,PRICE_CLOSE,i);
                        
MA22[i]=iMA(NULL,0,16,0,MODE_LWMA,PRICE_CLOSE,i);                                                       
                
//----   
if((MA1[i]>MA2[i]) && (MA11[i+1]<MA22[i+1]))  
//---- 
                                Alert( "speedMA(", Symbol(), ", ", Period(), ")  -  SIGNAL1!!!" );    

if((MA1[i]<MA2[i]) && (MA11[i+1]>MA22[i+1]))  
//---- 
                                Alert( "speedMA(", Symbol(), ", ", Period(), ")  -  SIGNAL2!!!" );   

   return(0);
  }
 

How do I get MathRand to work correctly, I get the same set of random numbers every time I run it. Which means they're not random.

 

How do I get MathRand to work correctly, I get the same set of random numbers every time I run it. Which means they're not random.