[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 466

 
Cmu4:

No... I did as you suggested - the same thing remains.

Also, I changed the code, dividing separately into opening and closing blocks by conditions. It's all the same. I do not know what to do now.

Here is a screenshot from the tester, EA for the tester is in the trailer:


You could go like this, with an open position control
Files:
 
Vinin:

Could be something like this, with control of open positions.


Also thought in this direction. But I am interested in the error itself. Where is it?

p.s. Thanks for adding to the code! When pompiled, it complains about undefined order_type, in Closeall function.

 
Cmu4:


Also thought in this direction. But I'm interested in the error itself. Where is it?

p.s. Thanks for adding to the code! When pompiling it, it swears about order_type undefined, in the Closeall function.


void Closeall(int OP=-1)
{
   for (int i=OrdersTotal()-1; i>=0; i--) 
   { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
      { 
         if(OrderSymbol()==Symbol())
         { 
            if (OrderType()==OP || OP=-1) 
            {
               if(OrderType()==OP_BUY)
                  OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
               else if(OrderType()==OP_SELL)
                  OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
            }
         } 
      }
   }
}
 
Cmu4:

No... I did as you suggested - the same thing remains.

Also, I changed the code, dividing separately into opening and closing blocks by conditions. It's all the same. I do not know what to do now.

Here is a screenshot from a tester, the Expert Advisor is in the trailer:

I need to know: Are positions opened in a row like this? Buy, Sell, Buy, Sell, etc. or consecutive ones, e.g. Buy.

I think you have Buy and Sell positions opening in succession.

The reason: the MACDs being compared are very close and change places (bigger is smaller) quickly. Therefore, one condition is met first and then the other.

Solution:

if (MA1-MA2 > 0.0001 &&  MA2-MA3 > 0.0001 && Napr==1) //или другая константа
 
extralifes:

no through if does not work.

It should be as long as the condition (d_mn_1>d_pl_1 && (d_mn_0-d_pl_0)>=2 is correct, to open only an order for a sell if iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)>0.7 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,0<0.7)

It is the same in reverse.

Can it be written through while or bool? I'm in a complete crunch in programming. I understand the logical chain, but my hands are slow to execute it in code.


So that's not the problem... everything should work through if... It works in that way - as long as (your same while ) the condition (d_mn_1>d_pl_1 && (d_mn_0-d_pl_0)>=2 - is fulfilled and RSI(NULL,0,rsi_period,PRICE_CLOSE,2)>0.7 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,0<0.7), then we open only profit...

You don't need any bool here - why should you deal with flags, when everything is clear that while all these conditions are fulfilled, we open either buy or sell orders?

total=OrdersTotal();
if(total<1)

{

  if (d_mn_1>d_pl_1 && (d_mn_0-d_pl_0)>=2 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)>0.7 &&  iRSI(NULL,0,rsi_period,PRICE_CLOSE,0<0.7)
        OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 3, /*Ask+10*Point*/0, /*Bid-10*Point*/0, "ADX sell", magic, 0, CLR_NONE);
   

  if (d_pl_1>d_mn_1 && (d_pl_0-d_mn_0)>=2 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)<0.3 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,0) > 0.3) 
       OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask, Digits), 3, /*Bid-10*Point*/0, /*Ask+10*Point*/0, "ADX buy", magic, 0, CLR_NONE);

  }

Look carefully once again.

Look for the error somewhere else in the code. You write "it doesn't work with if" - explain it in more detail - what does it say in the "log"?

 
ikatsko:

Hello! I don't want to (and sometimes do) hit a StopOut. I've decided to limit the lot to a value that would not "catch" StopOut in the worst conditions. Going through trial and error for a long time. Maybe someone has a solution?

Initial data:

- Currency pair - not necessarily EURUSD

- price (buy/sell price)

- a specified StopLoss in points (it is assumed that the worst-case scenario is not to catch a StopOut even if the StopLoss level is reached)

- specified lot value

- Other values should be filled out using MT4 functions: Size 1 lot, leverage, cross rate.

Preferably a code.

In theory, I understand what is needed: balance minus possible loss at StopLoss level divided by margin. And this value should be larger than the StopOut (in percentage terms).

Something like this

int level=AccountStopoutLevel(); ///// ТОЛЬКО ЕСЛИ ВЫРАЖЕН В ПРОЦЕНТАХ!!!
if (AccountStopoutMode==0)
  {
   double Marga = NormalizeDouble(MarketInfo("EURUSD", MODE_MARGINREQUIRED), 2);
   double TickValue = NormalizeDouble(MarketInfo("EURUSD", MODE_TICKVALUE), 2);
   int SL = 26;////Пунктов
   double lotsShortNaVSE = NormalizeDouble(AccountBalance() / (level * Marga / 100.0 + SL * TickValue ), 2);
  }

The number of lots must not be higher than the number of lotsShortNaVSE

SL ---- is a possible loss on your opened position.

And brokerage companies have their own perception of possible losses.

That is why we need to take the Maximal number from your or from the brokerage company. For example, at the moment the Dealer Center for the EURUSD pair has a possible loss SL = 26.

SL = MathMax(VashSLvPunktah, SLvPunktahUVashegoDillinga);
Are there any other options?
 
rlx:


And the brokerage companies also have their own view of the possible loss.

That's why you should take the maximum number of your or your brokerage company's loss. For example, at the moment the brokerage company has a possible loss SL = 26 for EURUSD.

Maybe there are some other variants?


That's just how to calculate this view of the DC.

But this is more critical for short-term traders.

 

I.e. for example if you have a stopLoss of 5 points. then naturally the number of open lots will be calculated a lot.

But to open such a position will not work, because brokerage companies have their own RiskManagement System.

 
rlx:


The only thing is how to calculate this view of the DC.

But this is more critical for short-termers.


Good day! Please help. I need a script that automatically sets stop and profit during manual trading. Do you think it's possible and if it exists, please give me a link.
 
Cmu4:

No... I did as you suggested - the same thing remains.

Also, I changed the code, dividing separately into opening and closing blocks by conditions. It's all the same. I do not know what to do now.

Here is a screenshot from the tester, EA for the tester is in the trailer:

As long as the MAKDak condition is met, orders will also open in batches on each tick.

Add to the conditions
For Buy positions: If there is NO market Buy order, then open it...
For Sell positions: If there is NO market Sell order, open it...

And the problem will be solved.

Reason: