PSAR trader v2

Author: Copyright � 2012, www.FxAutomated.com
Profit factor:
1.07
Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Indicators Used
Parabolic Stop and Reverse system
Miscellaneous
It issuies visual alerts to the screen
7 Views
0 Downloads
0 Favorites
PSAR trader v2
//+------------------------------------------------------------------+
//|                                               PSAR trader v2.mq4 |
//|                            Copyright © 2012, www.FxAutomated.com |
//|                                       http://www.FxAutomated.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, www.FxAutomated.com"
#property link      "http://www.FxAutomated.com"

//---- input parameters
extern double    Lots=0.1;
extern int       Slip=5;
extern string    StopSettings="Set stops below";
extern double    TakeProfit=50;
extern double    StopLoss=50;
extern string    PSARsettings="Parabolic sar settings follow";
extern double    Step    =0.001;   //Parabolic setting
extern double    Maximum =0.2;    //Parabolic setting
extern bool      CloseOnOppositeSignal=true;
extern string    TimeSettings="Set the hour range the EA should trade";
extern int       StartHour=0;
extern int       EndHour=23;
extern int       MagicNumber=220101;

string Trend;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

int StopMultd=10;
int Slippage=Slip*StopMultd;

int i,closesell=0,closebuy=0;

//------------------------------------------------------------

double  TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
double  SL=NormalizeDouble(StopLoss*StopMultd,Digits);


//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
  for(i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {
          if(OrderMagicNumber()==MagicNumber&&OrderSymbol()==Symbol()) {int halt=1;}


        }
     }
}
//-------------------------------------------------------------------+
// time check
//-------------------------------------------------------------------
if((Hour()>=StartHour)&&(Hour()<=EndHour))
{
int TradeTimeOk=1;
}
else
{ TradeTimeOk=0; }
//-----------------------------------------------------------------
// Bar checks
//-----------------------------------------------------------------

 
 //-------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------
// Opening criteria
//-----------------------------------------------------------------------------------------------------

// Open buy
 if((iSAR(NULL, 0,Step,Maximum, 0)<iClose(NULL,0,0))&&(iSAR(NULL, 0,Step,Maximum, 1)>iClose(NULL,0,1))&&(TradeTimeOk==1)&&(halt!=1)&&Trend!="BUY"){
 int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"PSAR trader buy order",MagicNumber,0,Blue);
 if(CloseOnOppositeSignal==true)closesell=1;
 Trend="BUY";
 }


// Open sell
 if((iSAR(NULL, 0,Step,Maximum, 0)>iClose(NULL,0,0))&&(iSAR(NULL, 0,Step,Maximum, 1)<iClose(NULL,0,1))&&(TradeTimeOk==1)&&(halt!=1)&&Trend!="SELL"){
 int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"PSAR trader sell order",MagicNumber,0,Green);
 if(CloseOnOppositeSignal==true)closebuy=1;
 Trend="SELL";
 }


//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
// Closing criteria
//-------------------------------------------------------------------------------------------------

if(closesell==1||closebuy==1||openbuy<1||opensell<1){// start

if(OrdersTotal()>0){
  for(i=1; i<=OrdersTotal(); i++){          // Cycle searching in orders
  
      if (OrderSelect(i-1,SELECT_BY_POS)==true){ // If the next is available
        
          if(OrderMagicNumber()==MagicNumber&&closebuy==1&&OrderSymbol()==Symbol()&&OrderType()==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE); }
          if(OrderMagicNumber()==MagicNumber&&closesell==1&&OrderSymbol()==Symbol()&&OrderType()==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE); }
          
          // set stops
          
                // Calculate take profit
                double tpb=NormalizeDouble(OrderOpenPrice()+TP*Point,Digits);
                double tps=NormalizeDouble(OrderOpenPrice()-TP*Point,Digits);
                // Calculate stop loss
                double slb=NormalizeDouble(OrderOpenPrice()-SL*Point,Digits);
                double sls=NormalizeDouble(OrderOpenPrice()+SL*Point,Digits);
          
          if((OrderMagicNumber()==MagicNumber)&&(OrderTakeProfit()==0)&&(OrderSymbol()==Symbol())&&OrderType()==OP_BUY){ OrderModify(OrderTicket(),0,OrderStopLoss(),tpb,0,CLR_NONE); }
          if((OrderMagicNumber()==MagicNumber)&&(OrderTakeProfit()==0)&&(OrderSymbol()==Symbol())&&OrderType()==OP_SELL){ OrderModify(OrderTicket(),0,OrderStopLoss(),tps,0,CLR_NONE); }
          if((OrderMagicNumber()==MagicNumber)&&(OrderStopLoss()==0)&&(OrderSymbol()==Symbol())&&OrderType()==OP_BUY){ OrderModify(OrderTicket(),0,slb,OrderTakeProfit(),0,CLR_NONE); }
          if((OrderMagicNumber()==MagicNumber)&&(OrderStopLoss()==0)&&(OrderSymbol()==Symbol())&&OrderType()==OP_SELL){ OrderModify(OrderTicket(),0,sls,OrderTakeProfit(),0,CLR_NONE); }

        }
     }
}


}// stop

//----
int Error=GetLastError();
  if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();}
  if(Error==133){Alert("Trading prohibited.");}
  if(Error==2){Alert("Common error.");}
  if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}

//----

//-------------------------------------------------------------------
   return(0);
  }
//+------------------------------END------------------------------------+
















































































int init()
  {
//----
   Alert("Visit www.FxAutomated.com for more goodies!");
//----
   return(0);
  }

Profitability Reports

USD/JPY Jul 2025 - Sep 2025
0.78
Total Trades 15
Won Trades 7
Lost trades 8
Win Rate 46.67 %
Expected payoff -3.98
Gross Profit 212.61
Gross Loss -272.30
Total Net Profit -59.69
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.71
Total Trades 13
Won Trades 5
Lost trades 8
Win Rate 38.46 %
Expected payoff -10.08
Gross Profit 313.43
Gross Loss -444.50
Total Net Profit -131.07
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
2.36
Total Trades 11
Won Trades 8
Lost trades 3
Win Rate 72.73 %
Expected payoff 13.50
Gross Profit 257.30
Gross Loss -108.85
Total Net Profit 148.45
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
1.00
Total Trades 8
Won Trades 4
Lost trades 4
Win Rate 50.00 %
Expected payoff 0.00
Gross Profit 200.00
Gross Loss -200.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
2.00
Total Trades 12
Won Trades 8
Lost trades 4
Win Rate 66.67 %
Expected payoff 16.67
Gross Profit 400.00
Gross Loss -200.00
Total Net Profit 200.00
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.71
Total Trades 16
Won Trades 7
Lost trades 9
Win Rate 43.75 %
Expected payoff -5.85
Gross Profit 231.98
Gross Loss -325.52
Total Net Profit -93.54
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
1.14
Total Trades 15
Won Trades 8
Lost trades 7
Win Rate 53.33 %
Expected payoff 2.20
Gross Profit 263.93
Gross Loss -230.93
Total Net Profit 33.00
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.65
Total Trades 19
Won Trades 8
Lost trades 11
Win Rate 42.11 %
Expected payoff -10.26
Gross Profit 355.10
Gross Loss -550.00
Total Net Profit -194.90
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.75
Total Trades 11
Won Trades 7
Lost trades 4
Win Rate 63.64 %
Expected payoff 13.64
Gross Profit 350.00
Gross Loss -200.00
Total Net Profit 150.00
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
1.01
Total Trades 38
Won Trades 19
Lost trades 19
Win Rate 50.00 %
Expected payoff 0.17
Gross Profit 643.15
Gross Loss -636.87
Total Net Profit 6.28
-100%
-50%
0%
50%
100%

Comments