Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1092

 
AlexandrL:
Reinstalling the OS. How to restore after OS reinstallation MT4 to the state it was in before reinstallation.
Indicators, Expert Advisors, scripts; templates, profiles; accounts
Before reinstallation copy the folder of the terminal on a flash drive. If the version is a 7 or higher, then the shared folder as well. Further details are available here
 

Afternoon.

An adviser based on an arrow indicator.

Sell on the upper fractal, buy on the lower one. In work max. 1 order. But there is an error somewhere, because the Expert Advisor does not take into account the fractals and opens only in buy. Or it won't open at all (if we change the offset in iCustom). I have tried to insert a different condition into the Expert Advisor (on the crossover of the arrow). Everything works, but it does not take data from the arrow indicator.

indicator:

//+------------------------------------------------------------------+
//|                                                   MI_Fractal.mq4 |
//|                                                     Орешкин А.В. |
//|                                        http://www.vk.com/mtforex |
//+------------------------------------------------------------------+
#property copyright "Орешкин А.В."
#property link      "http://www.vk.com/mtforex"

#property indicator_chart_window
#property indicator_buffers 2
#property  indicator_color1 Aqua
#property  indicator_color2 Yellow
#property  indicator_width1 2
#property  indicator_width2 2

//--- input parameters
extern int       leftBars=10;
extern int       rightBars=2;
extern int       difference=10;
//extern int       maximumBars=1000;
extern bool      showUp=true;
extern bool      showDown=true;

bool  UP_Fractal,DOWN_Fractal;
double DEF,up[],down[];

int init()
  {
   DEF=NormalizeDouble(difference*Point,Digits);
   SetIndexBuffer(0,up);
   SetIndexBuffer(1,down);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);    
   SetIndexArrow(0,217);
   SetIndexArrow(1,218);
   return(0);
  }

int deinit(){return(0);}

int start()
  {   
   //for (int i=maximumBars;i>rightBars;i--)
   for (int i=Bars-IndicatorCounted()-leftBars-1;i>rightBars;i--)   
      {//3
      UP_Fractal=true;DOWN_Fractal=true;
      
      for (int x=i+leftBars;x>=i-rightBars;x--)
         {//0
         if (x==i) continue;
         if (High[i]-High[x]<DEF) UP_Fractal=false;
         if (Low[x]-Low[i]<DEF) DOWN_Fractal=false;
         }//0
      
      up[i]=EMPTY;
      down[i]=EMPTY;
      
      if (showUp)   
         if (UP_Fractal && !DOWN_Fractal) up[i]=High[i];
      
      if (showDown)   
         if (!UP_Fractal && DOWN_Fractal) down[i]=Low[i]; 
      }//3
   return(0);
  }


Code from the owl:

double upFr=iCustom(Symbol(),0, "MI_Fractal",leftBars,rightBars,difference,showUp,showDown,0,1);
double downFr=iCustom(Symbol(),0, "MI_Fractal",leftBars,rightBars,difference,showUp,showDown,1,1); 
     
   if (upFr!=EMPTY_VALUE)   
   //if (upFr<2) 
   //if (upFr>0)    
     {   
                                          
      Alert(upFr); 
      Opn_S=true;                             
      //Cls_B=true;                                
     }
 if (downFr!=EMPTY_VALUE)
   //if (downFr<2)
 //  if (downFr>0)                                              
     {                                         
     Opn_B=true;                              
     //Cls_S=true;                             
     }

Tried all sorts of solutions already, it's not working. Please tell me where the error is.

Files:
 

Good afternoon.

Help me find the opening price of the first bar on Tuesday and fix it so that I can calculate from it all week.

Thank you.

 

Hello, I would be grateful if somebody could tell me what to put here so that the EA stops opening pending orders after they trigger.

//+------------------------------------------------------------------+
//| Copyright © 2014, Khlystov Vladimir |
//| http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, cmillion@narod.ru"
#property link "http://cmillion.ru"
#property strict
#property description "Expert Advisor trades on market surges without using any indicators."
#property description "The idea of the Expert Advisor is that stop orders are moved discretely in time at a given distance from the current price."
#property description "If the price has moved sharply enough in one direction, the EA simply does not have time to move the order and it becomes a market order."
#property description "Then a trall order is triggered."
//--------------------------------------------------------------------
extern int Stoploss = 10; // Stoploss, if 0, remains unchanged
Takeprofit = 50; //takeprofit, if 0, remains unchanged.
extern int TrailingStop = 10; //tramp length, if 0, then no trailing stop
extern int TrailingStart = 0; //when to include trall, for example after achievement of 40 pprofit.
extern int StepTrall = 2; //tramp step - move StopLoss no closer than StepTrall
extern int NoLoss = 0, //transfer to Breakeven at a specified number of points of profit, if 0, then no transfer to Breakeven
MinProfitNoLoss = 0; //minimum profit for the transfer to lossless.
extern int Magic = 77; //magic
extern int Step = 10; //distance from the price
extern double Lot = 0.1;
extern intern TimeModify = 30; //the number of seconds before which it is forbidden to modify an order
extern int slippage = 30; //maximal allowed price deviation for market orders (Buy and Sell orders).
//--------------------------------------------------------------------
datetime TimeBarB,TimeBarS;
//--------------------------------------------------------------------
int start()
{
double STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
double OSL=0,StLo=0,PriceB=0,PriceS=0,OOP=0,SL=0,TP=0;
int b=0,s=0,TicketB=0,TicketS=0,OT;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())
{
OT = OrderType();
OSL = NormalizeDouble(OrderStopLoss(),Digits);
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
SL=OSL;
if (OT==OP_BUY)
{
b++;
if (OSL<OOP && NoLoss!=0)
{
StLo = NormalizeDouble(OOP+MinProfitNoLoss*Point,Digits);
if (StLo > OSL && StLo <= NormalizeDouble(Bid - STOPLEVEL * Point,Digits)) SL = StLo;
}
if (TrailingStop>=STOPLEVEL && TrailingStop!=0 && (Bid - OOP)/Point >= TrailingStart)
{
StLo = NormalizeDouble(Bid - TrailingStop*Point,Digits);
if (StLo>=OOP && StLo > OSL+StepTrall*Point) SL = StLo;
}
if (SL > OSL)
{
if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error ",GetLastError(), "Order Modify Buy SL ",OSL,"->",SL);
else Print("Order Buy Modify SL ",OSL,"->",SL);
}
}
if (OT==OP_SELL)
{
s++;
if ((OSL>OOP || OSL==0) && NoLoss!=0)
{
StLo = NormalizeDouble(OOP-MinProfitNoLoss*Point,Digits);
if ((StLo < OSL || OSL==0) && StLo >= NormalizeDouble(Ask + STOPLEVEL * Point,Digits)) SL = StLo;
}
if (TrailingStop>=STOPLEVEL && TrailingStop!=0 && (OOP - Ask)/Point >= TrailingStart)
{
StLo = NormalizeDouble(Ask + TrailingStop*Point,Digits);
if (StLo<=OOP && (StLo < OSL-StepTrall*Point || OSL==0)) SL = StLo;
}
if ((SL < OSL || OSL==0) && SL!=0)
{
if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error ",GetLastError(), "Order Modify Sell SL ",OSL,"->",SL);
else Print("Order Sell Modify SL ",OSL,"->",SL);
}
}
if (OT==OP_BUYSTOP) {PriceB=OOP; TicketB=OrderTicket();}
if (OT==OP_SELLSTOP) {PriceS=OOP; TicketS=OrderTicket();}
}
}
}
if (b+TicketB==0)
{
if (Stoploss>=STOPLEVEL && Stoploss!=0) SL = NormalizeDouble(Bid - Stoploss * Point,Digits); else SL=0;
if (Takeprofit>=STOPLEVEL && Takeprofit!=0) TP = NormalizeDouble(Ask + Takeprofit * Point,Digits); else TP=0;
if (OrderSend(Symbol(),OP_BUYSTOP,Lot,NormalizeDouble(Ask+Step * Point,Digits),slippage,SL,TP, "news",Magic,0,CLR_NONE)!=-1) TimeBarB=TimeCurrent();
}
if (s+TicketS==0)
{
if (Stoploss>=STOPLEVEL && Stoploss!=0) SL = NormalizeDouble(Ask + Stoploss * Point,Digits); else SL=0;
if (Takeprofit>=STOPLEVEL && Takeprofit!=0) TP = NormalizeDouble(Bid - Takeprofit * Point,Digits); else TP=0;
if (OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Bid - Step * Point,Digits),slippage,SL,TP, "news",Magic,0,CLR_NONE)!=-1) TimeBarS=TimeCurrent();
}
if (TicketB!=0)
{
if (TimeBarB<TimeCurrent()-TimeModify && MathAbs(NormalizeDouble(Ask + Step * Point,Digits)-PriceB)/Point>StepTrall)
{
if (Stoploss>=STOPLEVEL && Stoploss!=0) SL = NormalizeDouble(Bid - Stoploss * Point,Digits); else SL=0;
if (Takeprofit>=STOPLEVEL && Takeprofit!=0) TP = NormalizeDouble(Ask + Takeprofit * Point,Digits); else TP=0;
if (OrderModify(TicketB,NormalizeDouble(Ask + Step * Point,Digits),SL,TP,0,CLR_NONE)) TimeBarB=TimeCurrent();
}
}
if (TicketS!=0)
{
if (TimeBarS<TimeCurrent()-TimeModify && MathAbs(NormalizeDouble(Bid - Step * Point,Digits)-PriceS)/Point>StepTrall)
{
if (Stoploss>=STOPLEVEL && Stoploss!=0) SL = NormalizeDouble(Ask + Stoploss * Point,Digits); else SL=0;
if (Takeprofit>=STOPLEVEL && Takeprofit!=0) TP = NormalizeDouble(Bid - Takeprofit * Point,Digits); else TP=0;
if (OrderModify(TicketS,NormalizeDouble(Bid - Step * Point,Digits),SL,TP,0,CLR_NONE)) TimeBarS=TimeCurrent();
}
}
return(0);
}
//--------------------------------------------------------------------

Files:
 
yaaarik777:

Good afternoon.

Help me find the opening price of the first bar on Tuesday and fix it so that I can calculate from it all week.

Thank you.

if (DayOfWeek() == 1) Price = iOpen(Symbol(), PERIOD_D1, 4);
if (DayOfWeek() >= 2) Price = iOpen(Symbol(), PERIOD_D1, DayOfWeek() - 2);

 

Looks like MetaTrader glitches: has anyone experienced a hang-up when trying to enter a procedure?

Here is a simple code

void OnInit()

{

...

Print("Outside procedure");

StartBuy(Price, Take, Stop, Lot);

...

}

void StartBuy(double Price, double Take, double Stop, double Lot)

{

Print("Inside procedure");

....

}

It produces one line Outside procedure and then the tester hangs. What is it?

 
A13ksandr:

Looks like MetaTrader glitches: has anyone experienced a hang-up when trying to enter a procedure?

Here is a simple code

void OnInit()

{

...

Print("Outside procedure");

StartBuy(Price, Take, Stop, Lot);

...

}

Stop trading in the inite, that's what it means. How many times have I told that inite must have a minimum of code with the fastest termination of execution, but still there is someone who is too lazy to read. There are standard predefined functions to run a program.

And the inite is like an int, not an input, with return of the reason for termination, by the way, I recommend to use it that way.

 
Scarick1:

Hello, I would be grateful if somebody could tell me what to put here so that the EA stops opening pending orders after they trigger.

//+------------------------------------------------------------------+
//| Copyright © 2014, Khlystov Vladimir |
//| http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, cmillion@narod.ru"
#property link "http://cmillion.ru"
#property strict
#property description "Expert Advisor trades on market surges without using any indicators."
#property description "The idea of the Expert Advisor is that stop orders are moved discretely in time at a given distance from the current price."
#property description "If the price has moved sharply enough in one direction, the EA simply does not have time to move the order and it becomes a market order."
#property description "Then a trall order is triggered."
//--------------------------------------------------------------------
extern int Stoploss = 10; // Stoploss, if 0, remains unchanged
Takeprofit = 50; //takeprofit, if 0, remains unchanged.
extern int TrailingStop = 10; //tramp length, if 0, then no trailing stop
extern int TrailingStart = 0; //when to activate a trall, for example after it reaches 40 points of profit
extern int StepTrall = 2; //tramp step - move StopLoss no closer than StepTrall
extern int NoLoss = 0, //transfer to Breakeven at a specified number of points of profit, if 0, then no transfer to Breakeven
MinProfitNoLoss = 0; //minimum profit for the transfer to lossless.
extern int Magic = 77; //magic
extern int Step = 10; //distance from the price
extern double Lot = 0.1;
extern intern TimeModify = 30; //the number of seconds before which it is forbidden to modify an order
extern int slippage = 30; //maximal allowed price deviation for market orders (Buy and Sell orders).
//--------------------------------------------------------------------

datetime TimeBarB,TimeBarS;

TradingAllowed = true;

//--------------------------------------------------------------------
int start()
{
double STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
double OSL=0,StLo=0,PriceB=0,PriceS=0,OOP=0,SL=0,TP=0;
int b=0,s=0,TicketB=0,TicketS=0,OT;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())
{
OT = OrderType();
OSL = NormalizeDouble(OrderStopLoss(),Digits);
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
SL=OSL;
if (OT==OP_BUY)

{

b++;

TradingAllowed = false;

if (OSL<OOP && NoLoss!=0)
{
StLo = NormalizeDouble(OOP+MinProfitNoLoss*Point,Digits);
if (StLo > OSL && StLo <= NormalizeDouble(Bid - STOPLEVEL * Point,Digits)) SL = StLo;
}
if (TrailingStop>=STOPLEVEL && TrailingStop!=0 && (Bid - OOP)/Point >= TrailingStart)
{
StLo = NormalizeDouble(Bid - TrailingStop*Point,Digits);
if (StLo>=OOP && StLo > OSL+StepTrall*Point) SL = StLo;
}
if (SL > OSL)
{
if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error ",GetLastError(), "Order Modify Buy SL ",OSL,"->",SL);
else Print("Order Buy Modify SL ",OSL,"->",SL);
}
}
if (OT==OP_SELL)
{

s++;

TradingAllowed = false;

if ((OSL>OOP || OSL==0) && NoLoss!=0)
{
StLo = NormalizeDouble(OOP-MinProfitNoLoss*Point,Digits);
if ((StLo < OSL || OSL==0) && StLo >= NormalizeDouble(Ask + STOPLEVEL * Point,Digits)) SL = StLo;
}
if (TrailingStop>=STOPLEVEL && TrailingStop!=0 && (OOP - Ask)/Point >= TrailingStart)
{
StLo = NormalizeDouble(Ask + TrailingStop*Point,Digits);
if (StLo<=OOP && (StLo < OSL-StepTrall*Point || OSL==0)) SL = StLo;
}
if ((SL < OSL || OSL==0) && SL!=0)
{
if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error ",GetLastError(), "Order Modify Sell SL ",OSL,"->",SL);
else Print("Order Sell Modify SL ",OSL,"->",SL);
}
}
if (OT==OP_BUYSTOP) {PriceB=OOP; TicketB=OrderTicket();}
if (OT==OP_SELLSTOP) {PriceS=OOP; TicketS=OrderTicket();}
}
}

}

if (b == 0 && s == 0) TradingAllowed = true;

if (b+TicketB==0 && TradingAllowed)
{
if (Stoploss>=STOPLEVEL && Stoploss!=0) SL = NormalizeDouble(Bid - Stoploss * Point,Digits); else SL=0;
if (Takeprofit>=STOPLEVEL && Takeprofit!=0) TP = NormalizeDouble(Ask + Takeprofit * Point,Digits); else TP=0;
if (OrderSend(Symbol(),OP_BUYSTOP,Lot,NormalizeDouble(Ask+Step * Point,Digits),slippage,SL,TP, "news",Magic,0,CLR_NONE)!=-1) TimeBarB=TimeCurrent();
}
if (s+TicketS==0 && TradingAllowed)
{
if (Stoploss>=STOPLEVEL && Stoploss!=0) SL = NormalizeDouble(Ask + Stoploss * Point,Digits); else SL=0;
if (Takeprofit>=STOPLEVEL && Takeprofit!=0) TP = NormalizeDouble(Bid - Takeprofit * Point,Digits); else TP=0;
if (OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Bid - Step * Point,Digits),slippage,SL,TP, "news",Magic,0,CLR_NONE)!=-1) TimeBarS=TimeCurrent();
}
if (TicketB!=0)
{
if (TimeBarB<TimeCurrent()-TimeModify && MathAbs(NormalizeDouble(Ask + Step * Point,Digits)-PriceB)/Point>StepTrall)
{
if (Stoploss>=STOPLEVEL && Stoploss!=0) SL = NormalizeDouble(Bid - Stoploss * Point,Digits); else SL=0;
if (Takeprofit>=STOPLEVEL && Takeprofit!=0) TP = NormalizeDouble(Ask + Takeprofit * Point,Digits); else TP=0;
if (OrderModify(TicketB,NormalizeDouble(Ask + Step * Point,Digits),SL,TP,0,CLR_NONE)) TimeBarB=TimeCurrent();
}
}
if (TicketS!=0)
{
if (TimeBarS<TimeCurrent()-TimeModify && MathAbs(NormalizeDouble(Bid - Step * Point,Digits)-PriceS)/Point>StepTrall)
{
if (Stoploss>=STOPLEVEL && Stoploss!=0) SL = NormalizeDouble(Ask + Stoploss * Point,Digits); else SL=0;
if (Takeprofit>=STOPLEVEL && Takeprofit!=0) TP = NormalizeDouble(Bid - Takeprofit * Point,Digits); else TP=0;
if (OrderModify(TicketS,NormalizeDouble(Bid - Step * Point,Digits),SL,TP,0,CLR_NONE)) TimeBarS=TimeCurrent();
}
}
return(0);
}
//--------------------------------------------------------------------

Somehow...


 
evillive:

Отставить торговать в ините, вот что значит. Сколько уже повторяли что в ините должен быть минимум кода с максимально быстрым завершением исполнения, всё равно найдется кто-нибудь, кому лень читать. Есть же стандартные предопределенные функции для работы программы.

Да и инит типа инт, а не войд, с возвратом причины прекращения работы, между прочим, рекомендую так им и пользоваться. 

Sorry! Of course everything happens in void OnTick(). I wrote myself)
 
A13ksandr:Sorry! Of course everything happens in void OnTick(). I wrote it down)
Then there's an error code in the tester's log, you can use it to figure it out.
Reason: