Questions from a "dummy" - page 238

 
forward666: When I run the robot, it immediately opens a position that obviously does not reflect the reality of the chart, so it goes into deep red. How do I make this position not open right away when I run the robot?
"The robot is a creature that its creator puts everything he (the creator) wants into, and everything he (the creator) is good at. If you think that everyone else on this forum knows what your "robot" is stuffed with, that's not entirely true.
 
Yedelkin:
A "robot" is a creature into which its creator puts whatever he (the creator) wants and is good at. If you think that everyone else on this forum knows what your "robot" is stuffed with, it's not quite true.
good point:)agree completely:)
 
there's nothing complicated about it! but the question still remains:)
 
forward666: There's nothing complicated about it!)
Could you applythe Styler in the editor and then paste the code correctly (SRC button)? Otherwise, with no editor at hand, it's hard to read.
MQL5.community - Памятка пользователя
MQL5.community - Памятка пользователя
  • 2010.02.23
  • MetaQuotes Software Corp.
  • www.mql5.com
Вы недавно зарегистрировались и у вас возникли вопросы: Как вставить картинку в сообщение на форуме, как красиво оформить исходный код MQL5, где находятся ваши Личные сообщения? В этой статье мы подготовили для вас несколько практических советов, которые помогут быстрее освоиться на сайте MQL5.community и позволят в полной мере воспользоваться доступными функциональными возможностями.
 
forward666:
#include <Trade/Trade.mqh>
#include <Trade/SymbolInfo.mqh>
#include <Trade/PositionInfo.mqh>

CTrade Trade;
CSymbolInfo Sym;
CPositionInfo Pos;

//--- input parameters
//input double Lots = 0.1; /*Lots*/ //position volume
input int Shift = 10; /*Shift*/ //the magnitude of jump in price to open the position
input int Limit=100; /*Limit*/ //Loss size in points to close position
input int Prof=10;
input int MA_Period=50; // Moving Average period

int maHandle; // indicator handle of Moving Average
double maVal[3]; // static array for storing values of Moving Average indicator


bool first;
double a,b,Lots;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{

maHandle=iMA(NULL,0,MA_Period,2,MODE_SMA,PRICE_CLOSE);
if(maHandle<0)
{
Alert("Error in creating indicators - error number: ",GetLastError(),"!");
return(-1);
}

first=false;

if(!Sym.Name(_Symbol))
{
Alert("CSymbolInfo initialization error, try again");
return(-1);
}

Print("Initialization of the Expert Advisor failed");

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

if(CopyBuffer(maHandle,0,0,3,maVal)<0)
{
Alert("Indicator buffer copy error - error number:",GetLastError());
return;
}

if(!Sym.RefreshRates())
{
return;
}

if(first)
{
a=Sym.Ask();
b=Sym.Bid();
first=false;
return;
}

Lots=AccountInfoDouble(ACCOUNT_FREEMARGIN)*0.66/1000/SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE);
Lots=MathMin(999,MathMax(1,Lots));
Lots=NormalizeDouble(Lots,2);


if(Pos.Select(_Symbol))
{
if(Pos.Profit()>2)
{
Trade.PositionClose(_Symbol,Sym.Spread()*2);
}
else
{
if(Pos.PositionType()==POSITION_TYPE_BUY)
{
if((Pos.PriceOpen()-Sym.Ask())/Sym.Point()>Limit)// || Sym.Bid()<maVal[0]-0.0005)
{
Trade.PositionClose(_Symbol,Sym.Spread()*2);

}
}
else if(Pos.PositionType()==POSITION_TYPE_SELL)
{
if((Sym.Bid()-Pos.PriceOpen())/Sym.Point()>Limit)// || Sym.Ask()>maVal[0]+0.0005)
{
Trade.PositionClose(_Symbol,Sym.Spread()*2);

}
}
}
}
else
{
if(b-Sym.Bid()>=Shift*Sym.Point() && maVal[0]>maVal[1] && maVal[1]>maVal[2] && Sym.Bid()<maVal[0])
{
Trade.SetDeviationInPoints(Sym.Spread()*2);
Trade.PositionOpen(_Symbol,ORDER_TYPE_SELL,Lots,Sym.Bid(),0,0,"); //Sym.Bid()+0.0030
// Trade.Sell(Lots,_Symbol,0,0,0,");
Print(__FUNCTION__,"():Sell");
}
if(Sym.Ask()-a>=Shift*Sym.Point() && maVal[0]<maVal[1] && maVal[1]<maVal[2] && Sym.Ask()>maVal[0])
{
Trade.SetDeviationInPoints(Sym.Spread()*2);
Trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,Sym.Ask(),0,0,"); //Sym.Ask()-0.0030
// Trade.Buy(Lots,_Symbol,0,0,0,");
Print(__FUNCTION__,"():Buy");
}
}

a=Sym.Ask();
b=Sym.Bid();
}
//+------------------------------------------------------------------+

	          
 

forward666:

If you want to insert a small piece of code, click on SRC as shown in the picture and insert the code. If there is as much code as you insert, attach the file with the code.

MQL5.community - Памятка пользователя
MQL5.community - Памятка пользователя
  • 2010.02.23
  • MetaQuotes Software Corp.
  • www.mql5.com
Вы недавно зарегистрировались и у вас возникли вопросы: Как вставить картинку в сообщение на форуме, как красиво оформить исходный код MQL5, где находятся ваши Личные сообщения? В этой статье мы подготовили для вас несколько практических советов, которые помогут быстрее освоиться на сайте MQL5.community и позволят в полной мере воспользоваться доступными функциональными возможностями.
 
paladin800:

forward666:

If you want to insert a small piece of code, click on SRC as in the picture and insert the code. If there is as much code as you insert, attach the file with the code.

Got it!
 
forward666:
Got it!
Who has a styler at hand, can you tell me where the error is, that the position opens immediately, it is not clear in which direction and it is not clear why?
 
forward666: Who has a styler at hand, can you tell me where the error is, that the position opens immediately, it is not clear in what direction and it is not clear why?
I will try to look it up on my computer in the evening. What is the "Styler" - look at the automatic link in your message.
 
Yedelkin:
I can't find anything with the code, I'll try to look it up on my computer in the evening. And what is the "Styler" - look at the link.

Thanks! If you can give me any tips, that would be great!

I'll read more about the styler.

Reason: