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

 
Vladislav Andruschenko:
Spread, if set to current. Test End Date if billed as current. There could be many more reasons.

Fixed Spread, End Date 01.01.18

 
Aidar Kaliaskar:

Fixed spread, End date 01.01.18


cost per point..... etc


try this weekend.

 

I am trying to make an indicator in MQL4, which would plot a line on "US.500+" chart by close prices from "US.30+". In general, the price lines of two symbols would be visible on one chart. Below is the code, but it does not work. In the log message "indicator on custom buffer is not supported yet". Teach me why it doesn't work. Opps.

#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_color1 clrRed
#property indicator_style1 STYLE_DOT
#property indicator_type1  DRAW_LINE
//---
input string   symbolName="US.30+"; // Symbol name
input double   difference=-22387.0; // Difference from other symbol
//--- price buffer for other symbol
double otherSymbol[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,otherSymbol,INDICATOR_DATA);
//---
   return INIT_SUCCEEDED;
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int     rates_total,
                const int     prev_calculated,
                const int     begin,
                const double &price[])
  {
//---
   for(int i=prev_calculated;i<rates_total;i++)
      otherSymbol[i+1]=iClose(symbolName,PERIOD_CURRENT,i)+difference;
   ArraySetAsSeries(otherSymbol,true);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Maxim Khrolenko:

I am trying to make an indicator in MQL4, which would plot a line on "US.500+" chart by close prices from "US.30+". In general, the price lines of two symbols would be visible on one chart. Below is the code, but it does not work. In the log message "indicator on custom buffer is not supported yet". Teach me why it doesn't work. Opps.

Because you have to use the first form of call.
 
Artyom Trishkin:
Because you have to use the first form of call.
Changed it and... it worked! Thank you very much.
 
STARIJ:

I found the reason - 60 seconds should be counted out of a loop

Thank you, thank you for the clarification.

If instead of 60 seconds it will be 300.

Position opening times are different, you need to write 300 seconds apart from the position opening time.

How should I do it?

 
lil_lil If it is 300 instead of 60 seconds ... you need to write at 300 second intervals from the time the position was opened. How do you do that?

Have you tried my program? I don't really understand 300... If you set 300 instead of 60, is it true? If you tell me how to get profit from it, I'll try to understand it better!

 

Help with the EA, as always the problem is probably trivial, but I haven't solved the conundrum

Should open buy ifema>smma fromema or not reaching itpoint(same for sell). Should close the deal at the close of the bar-open a new bar. The next open in the same way, but with a condition above theopening price of the previous one, that islast_order_price.

But in the end it opens where it wants and closes. (At the beginning of the test it opens and immediately closes)

#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

input int MA_period=10;
input int take=200, stop=200, Magic=1104;
input double lot=0.05;
input int slippage=30;
input int point=5;
double last_order_price,fast_MA,slow_MA;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   fast_MA=iMA(Symbol(),PERIOD_CURRENT,MA_period,0,MODE_EMA,PRICE_CLOSE,0);
   slow_MA=iMA(Symbol(),PERIOD_CURRENT,MA_period,0,MODE_SMMA,PRICE_CLOSE,0);
 
   if(fast_MA>slow_MA) last_order_price=0;
      else last_order_price=Ask+stop*_Point;

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   fast_MA=iMA(Symbol(),PERIOD_CURRENT,MA_period,0,MODE_EMA,PRICE_CLOSE,0);
   slow_MA=iMA(Symbol(),PERIOD_CURRENT,MA_period,0,MODE_SMMA,PRICE_CLOSE,0);
   
   if(Bid<=fast_MA+point*_Point && Bid>=fast_MA && fast_MA>slow_MA && SymOrder() && Bid>last_order_price)
   {
      OrderSend(Symbol(),OP_BUY,lot,Ask,slippage,Ask-stop*_Point,Ask+take*_Point,NULL,Magic,0,clrBlue);
      last_order_price=Bid;
   }
   
   if(Bid>=fast_MA-point*_Point && Bid<=fast_MA && fast_MA<slow_MA && SymOrder() && Bid<last_order_price)
   {
      OrderSend(Symbol(),OP_SELL,lot,Bid,slippage,Bid+stop*_Point,Bid-take*_Point,NULL,Magic,0,clrRed);   
      last_order_price=Bid;
   }
      
   if(!SymOrder() && Volume[0]<2 && OrderType()==OP_BUY)
   {
      OrderClose(OrderTicket(),lot,Bid,slippage,clrWhite); 
      
   }
   if(!SymOrder() && Volume[0]<2 && OrderType()==OP_SELL)
   {
      OrderClose(OrderTicket(),lot,Ask,slippage,clrWhite);  

   }     
      
  }
//+------------------------------------------------------------------+
bool SymOrder()
{
   for(int i=0; i<OrdersTotal(); i++)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) return false;
      }

   return true;
}
 
Roman Sharanov:

Help with the EA, as always the problem is probably trivial, but I haven't solved the conundrum

Should open buy ifema>smma fromema or not reaching itpoint(same for sell). Should close the deal at the close of the bar-open a new bar. The next open in the same way, but with a condition above theopening price of the previous one, that islast_order_price.

But in the end it opens where it wants and closes. (At the beginning of the test it opens and immediately closes)

How can I suggest? Save your code to the clipboard, write it in the Expert Advisor and run it in the strategy tester? Well, I will see that it opens and closes. So what? I may run it on a demo - today is Saturday, tomorrow is Sunday, the market is closed. Do you have to look at them with your eyes? Well, you have to keep in mind the values of all variables. There was earlier a method of debugging with a pencil and paper - try it. You can also put an Alert("Bid=", Bid, Fast+P=",Fast_Ema+point*_Point," ....) before all OrderSelect and OrderClose and set one day in the tester for example from February 19 to 20 and then after the test to open the log, make a copy, delete unnecessary lines and analyze. The MetaEditor also has a debugging feature. When you learn how to debug ... it will be great.
 

Where does it have a button?

Can you tell me how to align text in CSpinEdit control from #include <Controls\SpinEdit.mqh> (text field with increment).

By default it's aligned to the left edge, but I want it to be aligned to the right.

Reason: