Hello everyone. Ive been trying to figure this out for some time now but havnt been able to. Some help with this would be nice. The code below is what executes my long trades but I keep getting "OrderSend error 4051" "invalid lots amount for OrderSend function". Ive tried various ways but nothing seems to work. By using this code in my lot size im trying to get a lot size that will only risk my percent per trade but using a variable stoploss as reference. The stoploss changes from trade to trade since its the lowest low in 50 candle back. If you know of a better or easier way that would also be appreciated.
Edit: Im trying to incorporate risk/money management into my trades by doing this.
Variables Code:
Execution Code:
Edit: Im trying to incorporate risk/money management into my trades by doing this.
Variables Code:
Inserted Code
extern int Risk_Percent = 3; //Percent of my account to risk per trade. double LowestShift = iLowest(Symbol(), PERIOD_H1, MODE_LOW, 50, 1); //Find the candle with the lowest low in 50 candles back. double Lowest = iLow(Symbol(), PERIOD_H1, LowestShift); //Find the low of the candle found by LowestShift double Buy_Take_Profit = ((Bid-Lowest)+Ask); //To make the trade 1:1
Execution Code:
Inserted Code
if (Condition1 > Condition2) { if (Condition3 < Condition4) { if (Condition5 < Bid) { if (getOpenOrders() == 0) { double Buy_Lots = NormalizeDouble(((AccountBalance()*(Risk_Percent/100))/(((Bid-Lowest)*100000)*(MarketInfo(Symbol(),MODE_TICKVALUE)))),2); Buy_Order = OrderSend(Symbol(),OP_BUY,Buy_Lots,Ask,30,Lowest,Buy_Take_Profit,NULL,2000,0,clrGreen); } } } }