English

## Pls Help a Beginner, Thanks

 16 a2495432675 2016.01.26 12:25 #   Sorry I know where the "CalculateCurrentOrders" is used by searching the whole txt. This is too long for me, forgot after reading it through. thanks.Still have problems left.
12985
WHRoeder 2016.01.26 19:06 #

1.  Play video Please edit your post. For large amounts of code, attach it.

2. lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);  // it's trying to give the lot when trading, why do the math like this? really bad at math, also bad at english haha
Bogus calculation
• 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.
• Account Balance * percent = RISK = |OrderOpenPrice - OrderStopLoss| * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
• Do NOT use TickValue by itself - DeltaPerlot
• You must normalize lots properly and check against min and max.
• You must also check FreeMargin to avoid stop out

3. ```res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
return;```
Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
4. ```input double DecreaseFactor=3;      // please tell me what's this, all the things about it, I can not understand.
:
for(int i=orders-1;i>=0;i--){
:
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1)
lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);     // what the math work for ?```
• The loop assumes that history is ordered. It isn't necessarily. See Could EA Really Live By Order_History Alone? - MQL4 forum
• It counts the number of consecutive losses.
• One consecutive loss reduce lot by 1/DecreaseFactor, i.e. 2/3 normal. Two consecutive losses 1/3 normal. More trading stops.

5. `if(lot<0.1) lot=0.1;`
Don't hard code number; use
6. ` if(Volume[0]>1) return;`
Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
 16 a2495432675 2016.01.27 05:32 #   Thank you a loooot！
 16 a2495432675 2016.02.05 07:32 #   ```//--- go trading only for first tiks of new bar    if(Volume[0]>1) return; //--- get Moving Average    ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0); //--- sell conditions    if(Open[1]>ma && Close[1]ma)      {       res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);       return;      }```Thank you a looooot for your help!! Could you please teach me about those 3 returns above ? I'm confused by these returns. I read those C grammers again these days.I read first 7 chapters of C Primer Plus. But still confused. Why need return here, and what is the function of these return?Thank you again!