[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 280

 
veti-k:
Hi, how do i know how many pips an order is in profit?

For Buy - (Ask minus Bid) divided by Point

For Sell (Open Price minus Bid) divided by the Point

Although ... Buy will close at Bid, i.e. the difference between Ask and Bid, i.e. spread, will be lost of its profit in points. It is the same for the Sell, but it will be closed by Ask.

 
drknn:
What if he's got a code in there for 70 quid instead of 60? :) ;)
Let's save it for an upgrade :)
 
veti-k:
Hi, can you tell me how to find out how many pips an order is in profit?
If you have a buy position, you must subtract the opening price from the current Bid price. If it is a sell position, you should subtract the current Ask price from the opening price.
 
paladin80:
If a buy position is opened, subtract the opening price from the current Bid price. If the position is a sell position, subtract the current Ask price from the opening price.

The scouts found out that OrderClosePrice() can be used instead of Bid or Ask
 
Thank you))
 
Dear forum users, could you tell me how to put a variable from iCustom into ArrayMaximum?
 
Alexandr24:
Dear forum users, could you please advise how to put a variable from iCustom into ArrayMaximum ?
For this you need to read what ArrayMaximum is.

int ArrayMaximum( double array[], int count=WHOLE_ARRAY, int start=0)

It searches for the element with the maximal value. The function returns the position of the maximum element in the array.

The search is a process, not a variable. That is, you can assign an indicator value to an array element, and then search the array for the largest element with ArrayMaximum.
 
granit77:
For this you should read what ArrayMaximum is.

int ArrayMaximum( double array[], int count=WHOLE_ARRAY, int start=0)

Search for the element with the maximal value. The function returns the position of the maximal element in the array.

The search is a process, not a variable. That is, you can assign an indicator value to an array element and then search the array for the maximal element with ArrayMaximum.
How to find the maximal value of indicator for yesterday? I found the first and the maximal value of yesterday's day indicator, but I can't find the maximal value of yesterday's day, ArrayMaximum start searching through the whole chart, or may be it is done through another function?
 

Good afternoon all, I'm sitting in front of my computer banging my head against the keyboard - I can't fix one bug in the code... Please help a beginner.

Here is my owl code:

extern double TakeProfit = 500;

extern double Lots = 0.1;

extern double Stoploss = 30;

extern double TrailingStop = 30;

extern string Indicator_1 = "SAR (SAR_STEP)";

extern double SAR_Step = 0.02;

extern double SAR_MaxStep =0.2;

extern double GeneralShift = 0; // 0 - unclosed bar, 1 - closed.

// These are the variables that will be

// displayed during

// connection of the Expert Advisor with the chart


//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

int start()

{

double a;

int b;

int total, ticket, cnt;


//just variables to be used in the program


if(Bars<100)

{

Print("bars less than 100");

return(0);

}

// This condition checks if the chart history contains more than 100 candlesticks, and if not, it returns an error,

// it will generate an error. It is required to draw your attention to the problem of

// lack of information


if(TakeProfit<5)

{

Print("TakeProfit less than 5");

return(0);

}

// This condition checks TakeProfit level (one of the external variables,

// which controls profit taking level. It's needed to check whether // you've set the Take Profit levels.

// check if you set profit taking levels at a level not allowed by your brokerage company.

// Not allowed for your brokerage company. It's just so if your Expert Advisor fails, you // know exactly what the error is.

// where the error lies. I strongly recommend to set it.


total=OrdersTotal();

if(total<1)

// This check is needed, in order to avoid opening several identical positions at once. If it is not checked, then, for example, if your EA is triggered when stochastic is in the overbought zone, then it will trade on every tick until it has used up all of the margin.

// Therefore, in order to limit the number of open positions, this

// limiter. If it is set, then the Advisor will not open more than a certain // number of

// number of positions <x

{

// no open orders identified

if(AccountFreeMargin()<(1000*Lots))

{

Print("We have no money. Free Margin = ", AccountFreeMargin();

return(0);

}

// Another auxiliary piece of code. If there is not enough money in the account, it

// prints an error. This piece is completely useless if the Expert Advisor works

// real time, but it is very useful in testing on the history.


if(iSAR(NULL,0,SAR_Step,SAR_MaxStep,GeneralShift)>Close[0]); // Open BUY

// Finally we get to the most interesting part. Instead of these x's, we have to insert

// condition that triggers a BUY.


{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stoploss*Point, Ask+TakeProfit*Point, "comment",16384,0,Green);


// These are the Buy conditions. In principle, there is nothing to be changed here, but in order to broaden //my horizons, I widen the scope.

// I will decipher what it says here. It says here that we must buy

// (OP_BUY) the current symbol (currency pair, to the chart of which this Expert Advisor has been attached),

// trade size Lots (variable which is set at the beginning). Market price, with

// slippage 3, and with a StopLoss and TakeProfit set at the

at the // start, the trade will be marked with the comment "comment", with the determining number 0, and at the

// at the point of purchase, on the chart, there will be a green slider with the determining code

// 16384


if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}


// This block is only needed to log if everything went well.

// Or, otherwise, to record an error that caused something to fail.


// Now the same thing with the sell bet. Instead of YYYYYYY - condition

if(iSAR(NULL,0,SAR_Step,SAR_MaxStep,GeneralShift)<Close[0])

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss*Point,Bid-TakeProfit*Point, "macd sample",16384,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}


// Now the exit. Nothing has changed here either, it's just RRRRRR - condition

// close a trade by BUY, ZZZZZZZZZZ - by SELL


for(cnt=0;cnt

//for a while they look through all open positions

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && // check for opened positions

OrderSymbol()==Symbol()) // check for symbol

{

if(OrderType()==OP_BUY) // long position is opened

{

// should it be closed?

if(iSAR(NULL,0,SAR_Step,SAR_MaxStep,GeneralShift)<Close[0]) //close BUY.

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position

return(0); // exit

}

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else // Same with short position

{

// should it be closed?

if(iSAR(NULL,0,SAR_Step,SAR_MaxStep,GeneralShift)>Close[0])//close SELL

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position

return(0); // exit

}

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

}

return(0);

//--------

}

//-------- the end.

 

Budding auto trader can't catch a bug!!! PLEASE PLEASE HELP ME!!!!!!!!!!!!!!!!!!

'}' - unbalanced parentheses C:\Program Files (x86)\Forex4you MetaTrader 4\experts\Saurentios V101.mq4 (167, 1)