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

 
Hello all, I started reading the MQL4 tutorial (I want to learn how to program), but it's an old version, what would you advise to do? Read the tutorial and then the documentation?
 
LRA:
// ИХМО так нагляднее
Agreed!
 
linar:

Hello, I started to read the MQL4 tutorial (I want to learn how to program), but it is an old version, what would you advise to do?

If you have ever programmed in C, it is better to look through the source code of free indicators, simpler indicators and Expert Advisors and read the help.

If you have not programmed at all, then... If you don't know how to program at all, then read documentation. )))

There is also a tutorial on this forum: https://www.mql5.com/ru/forum/108883

 
A13ksandr:

It's just that at first the variable was called ProfitableSerie and had the opposite function. And there's something else to add.

Try it this way. I have a feeling something else will come up...

Another step forward - the bot opened one trade, but that's the end of it. Nothing else opens and there's not even a message in the log about any attempts...
 
alvlaf:
Another step forward - the bot opened one trade, but that was the end of it. The bot does not open anything else and there are no messages in the log about any attempts...

I wanted to put only part of the code correctly, but then I copied the whole code and did not fix the error. It should be like this in the last condition.

         if (GlobalVariableGet("AllowNewOrders") == 0) return;

But actually he shouldn't have made a single deal then. Some of the first two conditions are not working correctly. Fix the condition for now, let's see :)

Updade: bring back OnDeinit just in case.

void  OnDeInit()
{
   GlobalVariableSet("AllowNewOrders",1); 
} 
 
A13ksandr:

Damn, I wanted to insert only a part of the correct code originally, but then I copied the whole thing and did not correct this error. It should be like this in the last condition

But actually he shouldn't have made a single deal then. Some of the first two conditions are not working correctly. Fix the condition for now, let's see :)

Updade: bring back OnDeinit just in case.


Tried it, after one trade in minus started to open a position on every tick.
 
alvlaf:
Tried it, after one trade in minus started to open a position on every tick.

Put the first two conditions on the first line

if(GlobalVariableGet("AllowNewOrders") == 1) return;

And try the first test on one pair.

The broker GrandCapital?

 
A13ksandr:

Put the first two conditions on the first line

if (GlobalVariableGet("AllowNewOrders") == 1) return;

And try the first test on one pair.

Broker GrandCapital?

//----------------------------------------------------------------------
int OnInit()
{
if (!GlobalVariableCheck("AllowNewOrders")) GlobalVariableSet("AllowNewOrders",1);
return(INIT_SUCCEED);
}

//----------------------------------------------------------------------

void OnDeInit()
{
GlobalVariableSet("AllowNewOrders",1);
}
//----------------------------------------------------------------------

void OnTick()
{
if (GlobalVariableGet("AllowNewOrders") == 1) return;
{
if (CountTrades() == 0) // The number of orders must be equal to zero
{
if ((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))
// If the last trade is losing, the same one is opened, but with bigger lot
{
GlobalVariableSet("AllowNewOrders", 0);
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
return;
}
if (GlobalVariableGet("AllowNewOrders") == 1) return;
{
if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0)
// if last trade's profit is equal to zero, the same trade will be opened
{
GlobalVariableSet("AllowNewOrders", 0);
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder(), 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
return;
}
if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) > PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) < PriceOpenLastHistOrder(OP_SELL))
|| CountHistTrades() == 0)// If the last trade is profitable, the order is opened
{
if (GlobalVariableGet("AllowNewOrders") == 0) return;
if (SignalBuy() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic);
if (ticket>0) GlobalVariableSet("AllowNewOrders", 0);
return;
}
if (SignalSell() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);
if (ticket>0) GlobalVariableSet("AllowNewOrders", 0);
return;
}
}
}
GlobalVariableSet("AllowNewOrders", 1);
}
}

}

Yes, Grand Capital. Did you put it in right? It's stopped opening trades again.

 

Guys, I've already racked my brains. How do I make the EA place pending orders on highs and lows, e.g. 8 candles, with a take profit of 1/4.

I do something like this:

double Vhod1=iHighest(Symbol(),0,MODE_HIGH,8,0);

double Vhod2=iLowest(Symbol(),0,MODE_LOW,8,0);

double TP=((Vhod1-Vhod2)/4)+Vhod1;


I tried to change the parameters, but keeps getting wrong stops or sets the price at 7.00000; it is unclear where it's coming from

 
wishmast:

Guys, I've already racked my brains. How do I make the EA place pending orders on highs and lows, e.g. 8 candles, with a take profit of 1/4.

I do something like this:

double Vhod1=iHighest(Symbol(),0,MODE_HIGH,8,0);

double Vhod2=iLowest(Symbol(),0,MODE_LOW,8,0);

double TP=((Vhod1-Vhod2)/4)+Vhod1;


I tried to change the parameters, but keeps getting wrong stops or sets the price at 7.00000; it is unclear where it's coming from

iHighest, iLowest will give you the candlestick address, but not the price.
Reason: