Closing Trades if floating balace is in X% In negative - page 2

 
Adj007 #:
That will never be true, if your nominal negative_equity_balance is $100 that will still be lower than the floating meaning that the condition wont be true, hence the logic being incorrect.
if ((floatingBalance < -negative_equity_balance) || (floatingBalance < NewspercentageThreshold))

I got your point. But what if i swap this. It will check first condition and if it false, it will check second condition.

 
Revo Trades #:
start with li'l is is old, and i dont even know if it works anymore.

I am making changes to an old EA. it have 1500 lines of code under int start (). Just changing  the name from int start () to int Onstart () will make any issue to functions?

Revo Trades #:
The remainder of your posts, are confusing. I recommend that you pay a coder on Freelance to do it.

I have no budget and additionally, i am learning MQL Coding too :)

 
anuj71 #:

I got your point. But what if i swap this. It will check first condition and if it false, it will check second condition.

If you read from previous replies swapping them does not do anything, I've told you its the logic and the calculus. You need to find out how to calculate what you are looking for and then put this into logical code. You can't manipulate your existing code by swapping both conditions so that it runs if the code itself doesn't operate because the calculus is wrong. You need an entirely new logic and corrected calculations. 

 
Adj007 #:
If you read from previous replies swapping them does not do anything, I've told you its the logic and the calculus. You need to find out how to calculate what you are looking for and then put this into logical code. You can't manipulate your existing code by swapping both conditions so that it runs if the code itself doesn't operate because the calculus is wrong. You need an entirely new logic and corrected calculations. 


Conditions :

1. If floating Balance is less than -1% of account balance => Close the trade

(OR)

2. If floating balance is less than -$100 => Close the trade


This is what i want, Help me how i can write this condition?
 
anuj71 #:


Conditions :

1. If floating Balance is less than -1% of account balance => Close the trade

(OR)

2. If floating balance is less than -$100 => Close the trade


This is what i want, Help me how i can write this condition?

There should be some research on this, the equation is fairly simple, I believe if you start with that, it will be much easier to code. It seems you have panicselling() to close, you are just left with actually finding out how to do the calculation of what you are finding, the coding comes after figuring how to calculate.  

The account balance will be your main variable to use in the calculus along with the percentage threshold and a numerical figure(100) for a seperate condition, you just need to put them together and find a way around this, that's all I can push for help. 

 
Adj007 #:
panicselling()

Yes, i have Panic close functions.


Here is modified code with new logic :


void CheckAndCloseTradeOnNews()
  {
   if(NewsClosing && News_Trade_Status == "Paused")
     {
      double NewspercentageThreshold = 0.01 * negative_equity_percentage * Account_balance;
      News_Trade_Closing = "Active";
      if(symbolfloatingBalance < -negative_equity_balance)
        {
         f0_54();
         f0_15();
         f0_37();
         f0_22();
        }
     }
   else
      if(symbolfloatingBalance < NewspercentageThreshold)
        {
         f0_54();
         f0_15();
         f0_37();
         f0_22();
        }
      else
        {
         News_Trade_Closing = "Inactive";
        }
  }
 
anuj71:

Logic i am looking for :

If floating Balance is less than 1% in negative of account balance => Close the trade (OR) if floating balance is less than $100 in negative => Close the trade

That is not the logic you need. Control your risk.

Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin or leverage. No SL means you have infinite risk (on leveraged symbols). Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% account total.

  1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce, the stop goes below the support. Then you compute your lot size.

  2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/PIP, but it takes account of the exchange rates of the pair vs. your account currency.)

  3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
              MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum (2017)
              Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum (2018)
              Lot value calculation off by a factor of 100 - MQL5 programming forum (2019)

  4. You must normalize lots properly and check against min and max.

  5. You must also check Free Margin to avoid stop out

  6. For MT5, see 'Money Fixed Risk' - MQL5 Code Base (2017)

Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

 
why try to reinvent the wheel? There are plenty of examples of trade manangers on both this site and google. And most of those are working code. Use those and modify to suite your ideas.
 
anuj71 #:

I am making changes to an old EA. it have 1500 lines of code under int start (). Just changing  the name from int start () to int Onstart () will make any issue to functions?

I have no budget and additionally, i am learning MQL Coding too :)

sorry for the late reply.

changing the int start to int Onstart will turn the code into a script.

changing the int start to void OnTick will turn the code into modern EA, but also the math and instructions will be limited to 1 time per price tick, or 1 time for each change of price. (for most code).