Hello . You were right on the command , the placement was the issue .
It won't work now as its the weekend
#property strict enum Operation{ buy=OP_BUY, //BUY sell=OP_SELL, //SELL }; extern double Lots=0.01; //Specify position size, this is ignored if you use the Risk % extern bool UseRiskPercentage=false; //True if you want to use the risk % to calculate the size extern double RiskPercentage=2; //% of available balance to risk input Operation Command=buy; //Order type extern int TakeProfit=0; //Take Profit in pips extern int StopLoss=0; //Stop Loss in pips extern int Slippage=2; //Slippage in pips extern int MagicNumber=0; //Magic number if you want to specify one extern string Cmt=""; //Comment for the order if you want one input string sound="ok";//the sound to play //Function to normalize the digits double CalculateNormalizedDigits() { if(Digits<=3){ return(0.01); } else if(Digits>=4){ return(0.0001); } else return(0); } //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- //If Stop Loss is not set and risk % is in use stop the program, the stop loss is required if(StopLoss==0 && UseRiskPercentage){ Print("A stop loss is required if you are using a risk percentage"); return; } int Cmd=Command; //Normalize the digits and calculate the position size double nTickValue=MarketInfo(Symbol(),MODE_TICKVALUE); double nDigits=CalculateNormalizedDigits(); if(Digits==3 || Digits==5){ Slippage=Slippage*10; nTickValue=nTickValue*10; } if(UseRiskPercentage){ Lots=(AccountBalance()*RiskPercentage/100)/(StopLoss*nTickValue); Lots=MathRound(Lots/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP); } //Set the open, stop loss and take profit prices double OpenPrice=0; double TakeProfitPrice=0; double StopLossPrice=0; if(Cmd==OP_BUY){ OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits); if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice+TakeProfit*nDigits,Digits); if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice-StopLoss*nDigits,Digits); } if(Cmd==OP_SELL){ OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits); if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice-TakeProfit*nDigits,Digits); if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice+StopLoss*nDigits,Digits); } //Print on screen the informations to see what we are submitting Print("Opening an Order ",Command," size ",Lots, " open price ",OpenPrice," slippage ",Slippage," SL ",StopLossPrice," TP ",TakeProfitPrice," comment ",Cmt," magic ",MagicNumber); //Submit the order, check the it has been accepted int OrderNumber; OrderNumber=OrderSend(Symbol(),Cmd,Lots,OpenPrice,Slippage,StopLossPrice,TakeProfitPrice,Cmt,MagicNumber); if(OrderNumber>0){ Print("Order ",OrderNumber," open"); PlaySound(sound); } else{ Print("Order failed with error - ",GetLastError()); } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thank you anyone and everyone for your time and any assistance