Please just ignore the fact about my "profit statement" i know i got that wrong..
Here you have the code
void OnTick() { double High[]; datetime TimeCurrent; //if positions for this currency pair exist if(PositionSelect(_Symbol)==true) { // count down the number of positions until zero for(int i=PositionsTotal()-1; i>=0; i--) { //Calculate the ticket number ulong PositionTicket=PositionGetTicket(i); // calculate the currency pair string PositionSymbol=PositionGetString(POSITION_SYMBOL); // calculate the current position price double PositionPriceCurrent = PositionGetDouble(POSITION_PRICE_CURRENT); // calculate position open time datetime start =PositionGetInteger(POSITION_TIME); //Sort array downwards from the current candle ArraySetAsSeries(High,true); //fill array from position start to tocurrent time CopyHigh(_Symbol,PERIOD_CURRENT,TimeCurrent,start,High); // calculate the highest price int HighestCandel= ArrayMaximum(High,0,start); //Create an Array for prices MqlRates PriceInformation[]; //Sort it from start to current time ArraySetAsSeries(PriceInformation,true); //Copy price data into the array int Data=CopyRates(Symbol(),PERIOD_CURRENT,start,TimeCurrent,PriceInformation); // Get the position start price double SP=PositionGetDouble(POSITION_PRICE_OPEN); double HighestPrice=PriceInformation[HighestCandel].high; // Get the % price difference between price high and current double Profit = HighestPrice-SP; double Magisk = Profit*0.2; double Salj = HighestPrice-Magisk; if (PositionSymbol==_Symbol) { Comment( "Profit : ",Profit,"\n", "Sälj" ,Salj,"\n", "Current Price",PositionPriceCurrent,"\n", "Högsta" ,HighestPrice,"\n", "Start Pris" ,SP ); } //if End } //for end } // if end } // on Tic end
Tweeker:
Here you have the code
Rather than delve into the code, have you looked at the expert log, or run GetLastError() ? What does it tell you?
Here you have the code
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
Hi My Expert keeps on getting removed when i close my position
If im running this expert with an open position it works great, but as soon as i close the position and open a new one, the expert freezes and the gets removed
Why?