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

 

Tell me, if I'm not an expert in programming.

Does this thing look at the history when opening an order or not?

extern int dDay;
//extern bool fl;

int init()
  {
      return(0);
  }

int deinit()
  {
      return(0);
  }

int start()
  {
      double MA2,MA3;
      double Fr,Fr1;
      double SAR;
      double prof;
      int total,cnt;
      
      MA2 = iMA(NULL,0,2,0,MODE_SMA,PRICE_CLOSE,0);
      MA3 = iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,0);
      Fr = iForce(NULL,0,2,MODE_SMA,PRICE_CLOSE,0);
      Fr1 = iForce(NULL,0,2,MODE_SMA,PRICE_CLOSE,1);
      
      //SAR = iSAR(NULL,0,0.2,2,0);
      
      if((Hour() == 22) && (OrdersTotal() == 0) && (dDay != Day()))
      {
         //if(Open[0] > MA) // BUY
         if(MA3 < MA2)
         //if(SAR < Open[0])
         {
            OrderSend(Symbol(),OP_BUY,1,Ask,3,0,Ask+0.0010,"",2,0,Blue);
            //fl = true;
         }
         //if(Open[0] < MA) // SELL
         if(MA3 > MA2)
         //if(SAR > Open[0])
         {
            OrderSend(Symbol(),OP_SELL,1,Bid,3,0,Bid-0.0010,"",1,0,Red);
            //fl = true;
         }
      
         dDay = Day();
      }
      
      /*if((Hour() == 8) && (OrdersTotal() == 1) && fl)
      {
         fl = false;
         if(OrdersTotal() != 0)
         {
            total = OrdersTotal();
            for(cnt=0;cnt<total;cnt++)
            {  
               OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);         
               prof = OrderProfit() / 10;
               if(prof <= -10)
               {
                  if(OrderType()==OP_BUY)
                  {
                     OrderClose(OrderTicket(), OrderLots(), Bid, 3, Yellow);   
                     OrderSend(Symbol(),OP_SELL,1,Bid,3,0,Bid-0.0010,"",1,0,Red);
                  }
                  if(OrderType()==OP_SELL)
                  {
                     OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);
                     OrderSend(Symbol(),OP_BUY,1,Ask,3,0,Ask+0.0010,"",2,0,Blue);
                  }
               }
            }
         }
      }*/
  
      
      if(OrdersTotal() != 0)
      {
         total = OrdersTotal();
         for(cnt=0;cnt<total;cnt++)
         {  
            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);                     
            prof = OrderProfit() / 10;
            if(prof >= 4)
            {
               if(OrderType()==OP_BUY)
               {
                  OrderClose(OrderTicket(), OrderLots(), Bid, 3, Yellow);   
               }
               if(OrderType()==OP_SELL)
               {
                  OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);
               }
            }
         }
      }

      return(0);
  }
 
baykanur:

Tell me, if I'm not good at programming.

does this thing look in the history when opening an order or not ?



1) use the SRC tag when inserting code

2) delete what is commented out.

3) tell us what you want to see and what the discrepancy is

 
ilunga:

1) use the SRC tag when inserting code

2) remove what is commented out

3) tell me what you want to see and what is the discrepancy

src inserted

What is commented out?

there is a discrepancy in the number of profitable deals in the tester, that's why I asked

 

I want to learn how to draw levels on the chart depending on the indicator values in a separate window. For example, if the MACD crosses level 0 from bottom to top, a line is drawn on the chart according to the Low of the bar where the crossing occurs. When the MACD is crossed from the top downwards, the line on High will be drawn accordingly. I have written something, it compiles without errors, but nothing happens. Can you help me please?

#property  indicator_chart_window
#property  indicator_buffers 1
#property  indicator_color1  Blue

double    Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buffer);

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   double level;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=0; i<limit; i++)
      
      double    macd = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
      double    macd1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i+1);
      
      if (macd > 0 && macd1 < 0)
      {
      level = iLow("EURUSD",PERIOD_M1,i); //Почему выскакивает ощибка если написать просто iLow[i]?
      Buffer[i]=level;
      }
      else if (macd < 0 && macd1 > 0)
      {
      level = iHigh("EURUSD",PERIOD_M1,i); //Почему выскакивает ощибка если написать просто iHigh[i]?
      Buffer[i]=level;
      }
   return(0);
  }
 
baykanur:

src inserted

I do not know what has been commented

there is a discrepancy in the number of profitable trades in the tester

there are always 2 objects in the match that are compared.

does the tester not match the demo on the same period? For example, because the spread in the tester is different

 
Ichimo:

I want to learn how to draw levels on the chart depending on the indicator values in a separate window. For example, if the MACD crosses level 0 from bottom to top, a line is drawn on the chart according to the Low of the bar where the crossing occurs. When the MACD is crossed from the top downwards, the line on High will be drawn accordingly. I have written something, it compiles without errors, but nothing happens. Please help.

line is at least 2 points ;)

Buffer[i]=level;

it's one point, the adjacent ones are probably zero. that's why the line has nowhere to be drawn

 //Почему выскакивает ощибка если написать просто iLow[i]?
because Low[i] has no "i" at the beginning
 
Vinin:

Where is that basket?
I can direct you to your basket... :)
 
Is there any way to divide the distance between the two prices into 3-4 parts, not just divide them, but also know the price of each of the resulting parts?
 
sss2019:
Is there any way to divide the distance between the two prices into 3-4 parts, not just divide them, but also know the price of each of the resulting parts?
double price1;

double price2;

...

if (price1 > price2)
{
   double delta = price1 - price2;
   double level1 = price2 + delta*0.25;
   double level2 = price2 + delta*0.5;
   double level3 = price2 + delta*0.75;
}
=)
 
ilunga:

a line is at least 2 points ;)

this is one point, the neighbouring ones are probably zero. therefore there is nowhere to draw the line

because Low[i] has no "i" at the beginning



So, I either need to create a previous point or draw an Arrow instead of a line. Thanks, I'll keep racking my brains.