#property version "1.00"
#property strict
#property description "This Expert Advisor opens orders when the PSAR changes from above to below the price or vice versa"
#property description " "
#property description "DISCLAIMER: This code comes with no guarantee, you can use it at your own risk"
#property description "We recommend to test it first on a Demo Account"
/*
ENTRY BUY: PSAR changes from above the previous bar to below the current bar
ENTRY SELL: PSAR changes from below the previous bar to above the current bar
EXIT: Take profit or trailing stop using PSAR
*/
extern double LotSize=0.1; //Position size
extern double StopLoss=20; //Stop loss in pips
extern double TakeProfit=500; //Take profit in pips
extern int Slippage=2; //Slippage in pips
extern bool TradeEnabled=true; //Enable trade
extern double PSARStep=0.2; //PSAR Step
extern double PSARMaxStep=0.02; //PSAR Max Step
extern int MagicNumber=11223344; //Magic Number to assign to the orders
double ePoint; //Point normalized
bool CanOrder; //Check for risk management
bool CanOpenBuy; //Flag if there are buy orders open
bool CanOpenSell; //Flag if there are sell orders open
int OrderOpRetry=10; //Number of attempts to perform a trade operation
int SleepSecs=3; //Seconds to sleep if can't order
int MinBars=60; //Minimum bars in the graph to enable trading
double MinSL;
double MaxSL;
double TP;
double SL;
double Spread;
int Slip;
void Initialize(){
RefreshRates();
ePoint=Point;
Slip=Slippage;
if (MathMod(Digits,2)==1){
ePoint*=10;
Slip*=10;
}
TP=TakeProfit*ePoint;
SL=StopLoss*ePoint;
CanOrder=TradeEnabled;
CanOpenBuy=true;
CanOpenSell=true;
}
void CheckCanOrder(){
if( Bars<MinBars ){
Print("INFO - Not enough Bars to trade");
CanOrder=false;
}
OrdersOpen();
return;
}
void OrdersOpen(){
for( int i = 0 ; i < OrdersTotal() ; i++ ) {
if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) {
Print("ERROR - Unable to select the order - ",GetLastError());
break;
}
if( OrderSymbol()==Symbol() && OrderType() == OP_BUY) CanOpenBuy=false;
if( OrderSymbol()==Symbol() && OrderType() == OP_SELL) CanOpenSell=false;
}
return;
}
void CloseAll(int Command){
double ClosePrice=0;
for( int i = 0 ; i < OrdersTotal() ; i++ ) {
if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) {
Print("ERROR - Unable to select the order - ",GetLastError());
break;
}
if( OrderSymbol()==Symbol() && OrderType()==Command) {
if(Command==OP_BUY) ClosePrice=Bid;
if(Command==OP_SELL) ClosePrice=Ask;
double Lots=OrderLots();
int Ticket=OrderTicket();
for(int j=1; j<OrderOpRetry; j++){
bool res=OrderClose(Ticket,Lots,ClosePrice,Slip,Red);
if(res){
Print("TRADE - CLOSE - Order ",Ticket," closed at price ",ClosePrice);
break;
}
else Print("ERROПоказано первые 50% кода (символов: 4860)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.