Help with quotOrderSend error 4051quot
Page 1 of 502 12 LastLast
Results 1 to 10 of 13

Thread: Help with quotOrderSend error 4051quot

  1. #1
    Hello everyone. Ive been trying to figure this out for some time now but havnt been able to. Some help with this would be fine. The code below is what implements my long transactions but I keep receiving OrderSend mistake 4051 invalid lots sum for OrderSend function. Ive tried different methods but nothing seems to work. By using this code within my lot dimensions im trying to get a lot dimensions that is only going to risk my percentage per trade but using a variable stoploss in reference. The stoploss varies from trade to trade since its the lowest low in 50 candle back. If you know of a simpler or better way that would also be valued.

    Edit:'m seeking to incorporate risk/money management into my transactions using this method.

    Variables Code:
    Inserted Code extern int Risk_Percent = 3; //Percent of the account to risk per trade. Dual LowestShift = iLowest(Symbol(), PERIOD_H1, MODE_LOW, 50, 1); //Find the candle using the lowest non in 50 candles back. Double Lowest = iLow(Symbol(), PERIOD_H1, LowestShift); //Find the low of the candle utilized by LowestShift double Buy_Take_Profit = ((Bid-Lowest) Ask); //To make the trade 1:1
    Execution Code:
    Inserted Code if (Condition1 gt; Condition2) if (Condition3 lt; Condition4) if (Condition5 lt; Bid) if (getOpenOrders() == 0) double Buy_Lots = NormalizeDouble(((AccountBalance()*(Risk_Percent/100))/(((Bid-Lowest)*100000)*(MarketInfo(Symbol(),MODE_TICKVALU E)))),2); Buy_Order = OrderSend(Symbol(),OP_BUY,Buy_Lots,Ask,30,Lowest,B uy_Take_Profit,NULL,2000,0,clrGreen);

  2. #2
    Thank you. I do that and im. It appears the part where Risk_Percent is divided by 100 provides me back 0 in the print. If I change the risk to 100 then it gives me . It doesnt appear to need to give me a decimal though.

    I will check on the lot minimum but I think that the above is the main reason behind the error. Still a min and a maximum aren't bad things to plan in.

    I will change it to equity. Why would I must look at the free margin?

  3. #3
    Quote Originally Posted by ;
    Thank you for the answer. I had been doing just that and im coming back with additional information. It seems the area where Risk_Percent is divided by 100 gives me in the print. If I alter the risk to 100 then it gives me . It doesnt appear to want to give me a decimal though. I will check on the lot minimum but I feel that the above is the reason for the mistake. Still a min and a maximum are not bad things to plan in. I'll change it . Why would I have to check the free margin?
    Ernie11-
    Risk_Percent should be defined as a double
    double Risk_Percent = 0.30;//Percentage of the account to risk per trade.

  4. #4
    Thank you for the reply. I got it working by performing Risk_Percent*0.01 rather than Risk_Percent/100. Dont understand why one works and the other doesn't, they both give the exact same answer. If I left the Risk_Percent a double I wouldn't be able to alter it in the input box ? It would always be a value?

    I want to implement a particular trailing stop but im having a small amount of difficulties with it also. I would like it to start a trailing stop once it gets to Xpercent between OpenOrderPrice and Take_Profit. Can you have a look at it please. The elements in bold are the only ones I shifted from a normal trailing stop.

    Factors:
    Inserted Code extern int Start_Trailing_Stop_Percent = 70; extern int Trailing_Stop = 100; double LowestShift = iLowest(Symbol(), PERIOD_H1, MODE_LOW, 50, 1); double HighestShift = iHighest(Symbol(), PERIOD_H1, MODE_HIGH, 50, 1); double Lowest = iLow(Symbol(), PERIOD_H1, LowestShift); double Maximum = iHigh(Symbol(), PERIOD_H1, HighestShift); double Buy_Take_Profit = ((Bid-Lowest) Ask); double Sell_Take_Profit = (Bid-(Highest-Ask));
    Trailing Stop:
    Inserted Code for(int I=0;ilt;OrdersTotal();I ) { //Select Open trades if(OrderSelect(I,SELECT_BY_POS,MODE_TRADES) == false) {} //Perform monitoring stop on buy trade if (OrderType() == OP_BUY OrderSymbol() == Symbol()) { if(Trailing_Stopgt;0) { #91;b#93;if(Bidgt;-LRB-(((Start_Trailing_Stop_Percent*0.01)*(Buy_Take_Pro fit-OrderOpenPrice())))) OrderOpenPrice()) {#91;/b#93; if(OrderStopLoss()lt;Bid-Point*Trailing_Stop) { if(OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*Trailing_Stop,OrderTakeProfit(),0,clrGreen)) return; else {} } } } } //Perform monitoring stop on Sell trade if(OrderType() == OP_SELL OrderSymbol() == Symbol()){ if(Trailing_Stopgt;0) { #91;b#93;if(Asklt;(OrderOpenPrice()-((((Start_Trailing_Stop_Percent*0.01)*(OrderOpenPr ice()-Sell_Take_Profit)))))) {#91;/b#93; if((OrderStopLoss()gt;(Ask Point*Trailing_Stop)) || (OrderStopLoss()==0)) { if(OrderModify(OrderTicket(),OrderOpenPrice(),Ask Point*Trailing_Stop,OrderTakeProfit(),0,clrRed)) return; else {} } } } } }

  5. #5
    Quote Originally Posted by ;
    Thank you for the answer. I got it working by doing Risk_Percent*0.01 rather than Risk_Percent/100. Dont know why one works and the other doesn't, they both offer the identical answer. If I made the Risk_Percent a double I wouldn't have the ability to alter it from the input box ? It would always be a fixed value? I wish to execute a special trailing stop but im having a little bit of problems with it also. I want it to start a trailing stop once it gets to X% between OpenOrderPrice and Take_Profit. Can you have a look please. The components in bold...
    Ernie11-
    Yes you can just add the extern facing it.

    As to the monitoring stop, I wouldn't consider working on it without the entire EA code.

  6. #6
    I will join the EA. Everything thats a print I put in trying to trouble shoot it. I noticed the OrderOpenPrice() in the Buy Logic isnt exactly the same as the open price when backtesting. Thanks for taking the time to check at it.
    https://forexintuitive.com/attachmen...2088120550.mq4

  7. #7
    Quote Originally Posted by ;
    I will attach the EA. Everything thats a print I place in trying to trouble shoot it. I noticed the OrderOpenPrice() from the Buy Logic isnt the same as the available price when backtesting. Thanks for taking the time to check at it. file
    Ernie11-
    I've made some alterations to it - seems to work at the ST.
    https://forexintuitive.com/attachmen...5186796309.mq4

  8. #8
    Hi cyber1. Thanks for the help, I just ran it once to see if it works and it does. First time I implement the money management component so will see how that works out. That is suppose to help so one transaction isnt bigger than the other.

  9. #9
    Hi cyber1. I noticed im getting a bit of OrderModify 130s from running it. Do you know why? Also it moves the stoploss into the % inputted but doesnt trail it from there, I will attempt to bring this component with everything you wrote.

  10. #10
    Hi cyber1. Im not getting anymore of these errors and I got it to track the bid/ask after reaching the beginning point (BEPoint) as you put it. I do have a query about your code however. The part that calls the Trailing_Control is only activated once each bar? Which means that the Stoploss will simply be upgraded once per bar?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners more information