Need help for simple script using parabolic SAR

 

Hey everyone!

I really don't know anything about this specific programming language yet and all I want to do is get alerted by email when the 30minute parabolic sar changes. Can someone help me out? Thanks alot!

-Arie

[Deleted]  

N

By 'Change', what do you mean?

Move inside the bar?

Move above/below the low/high or pivot of the bar?

-BB-

 
Yeah... I'm talking about an actual reversal, where the dot moves to above the high from below the low and vice versa.
[Deleted]  

Example below

Dont get excited, the EA doesnt make money! Its a demo of various methods.

For you it shows SendMail, method of calling iSAR, use of a 'static' value to remember <the last direction>

FWIW

-BB-

 
#property copyright "bd@selectfx.net"
#property link "http://www.selectfx.net"
// RUN ON THE H4 CHART TO LIMIT EXECUTIONS
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
 
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
 
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int iPeriod=PERIOD_H4;
int iStopLoss=400, iTakeProfit=1500;
int iStopLossTight=200, iTakeProfitTight=1000;
string strSymbol="GBPUSD";
double iAction=0; // 1=Buy, 2=Sell
int iMagicBuy=2233;
int iMagicSell=5566;
string strAction;
int i, iGetMore;
// static int iDay=0;
// static int iYesterday=0;
static int iCurrentDirection=0;
int iTotal;
double ticketBuy, ticketSell;
 
if(iBars(strSymbol,iPeriod)<4)
{
Print("Bars less than 4");
return(0); 
}
/*
iDay=TimeDayOfYear(TimeCurrent());
 
if (iDay == iYesterday) {return(0);} // Quit
else {iYesterday=iDay;} // Change value & proceed
*/
 
if (Volume[0]>1) {return(0);}
 
iAction=SARResult(strSymbol, iPeriod); 
 
// ================= SendMail Example ==============================
 
if ((iCurrentDirection != iAction) && (iAction==1)) SendMail("SAR Reversal", "Buy Signal");
if ((iCurrentDirection != iAction) && (iAction==2)) SendMail("SAR Reversal", "Sell Signal"); 
 
 
// ================= SendMail Example ==============================
 
if(iAction==1) // Trend up starting
{
//Close any Sell orders this Expert opened
CloseAllSellOrders(strSymbol);
 
iCurrentDirection=1; // i.e. Buy
 
ticketBuy=OrderSend(strSymbol,OP_BUY,1,Ask,5,Ask-iStopLoss*Point,Ask+iTakeProfit*Point,"BD buy Start Trend",iMagicBuy,0,Green);
 
}
 
 
if(iAction==2) // Trend down starting
{
//Close any Buy orders this Expert opened
CloseAllBuyOrders(strSymbol);
 
iCurrentDirection=2; // i.e. Sell
 
ticketSell=OrderSend(strSymbol,OP_SELL,1,Bid,5,Bid+iStopLoss*Point,Bid-iTakeProfit*Point,"BD sell Start Trend",iMagicSell,0,Red);
 
}
 
if(iAction==0) // Between trend changes
{
iGetMore = ADX_ApprovesMore(strSymbol, iPeriod, iCurrentDirection);
 
if(iCurrentDirection==1 && iGetMore==1)
{
ticketBuy=OrderSend(strSymbol,OP_BUY,1,Ask,5,Ask-iStopLossTight*Point,Ask+iTakeProfitTight*Point,"BD buy Mid-Trend",iMagicBuy,0,Green);
}
 
if(iCurrentDirection==2 && iGetMore==1)
{
ticketSell=OrderSend(strSymbol,OP_SELL,1,Bid,5,Bid+iStopLossTight*Point,Bid-iTakeProfitTight*Point,"BD sell Mid-Trend",iMagicSell,0,Red);
}
}
 
 
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| find trend change direction using PSAR |
//+------------------------------------------------------------------+
int SARResult(string strSymbol, int iPeriod)
{
/* 
R4 = R3 + RANGE (same as: PP + RANGE * 3)
R3 = R2 + RANGE (same as: PP + RANGE * 2)
R2 = PP + RANGE
R1 = (2 * PP) - LOW
PP = (HIGH + LOW + CLOSE) / 3 or PP6=(H+L)/2
S1 = (2 * PP) - HIGH
S2 = PP - RANGE
S3 = S2 - RANGE (same as: PP - RANGE * 2)
S4 = S3 - RANGE (same as: PP - RANGE * 3)
*/
double dAccell=0.02, dMax=0.2;
int iDirection1, iDirection2; // 1=Up, 2=Down
 
if((iSAR(strSymbol,iPeriod,dAccell,dMax,1)<Low[1]) && (iSAR(strSymbol,iPeriod,dAccell,dMax,0)>Low[0])) //Downtrend
{return(2);}
if((iSAR(strSymbol,iPeriod,dAccell,dMax,1)>High[1]) && (iSAR(strSymbol,iPeriod,dAccell,dMax,0)<High[0])) //Uptrend
{return(1);}
return(0);
}
 
 
void CloseAllBuyOrders(string strSymbol)
{
int i, iTotalOrders;
 
iTotalOrders=OrdersTotal(); 
 
for (i=0; i<iTotalOrders; i++)
{ 
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{ 
if (OrderSymbol()==strSymbol)
{ 
if (OrderType()==OP_BUY) 
OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
if (OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT) 
OrderDelete(OrderTicket());
}
}
}
}
void CloseAllSellOrders(string strSymbol)
{
int i, iTotalOrders;
 
iTotalOrders=OrdersTotal(); 
 
for (i=0; i<iTotalOrders; i++)
{ 
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{ 
if (OrderSymbol()==strSymbol)
{ 
if (OrderType()==OP_SELL) 
OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet);
if (OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT ) 
OrderDelete(OrderTicket());
}
}
}
}
int ADX_ApprovesMore(string strSymbol, int iPeriod, int iDirection)
{
double dADX1, dADX2, dDMIplus1, dDMIminus1, dDMIplus2, dDMIminus2;
 
// Get values - note 5 day parameter for ADX, 14 is too laggy
dADX1=iADX(strSymbol, iPeriod, 5, PRICE_CLOSE,MODE_MAIN,0);
dADX2=iADX(strSymbol, iPeriod, 5, PRICE_CLOSE,MODE_MAIN,1);
 
dDMIplus1=iADX(strSymbol, iPeriod, 5, PRICE_CLOSE,MODE_PLUSDI,0);
dDMIplus2=iADX(strSymbol, iPeriod, 5, PRICE_CLOSE,MODE_PLUSDI,1);
 
dDMIminus1=iADX(strSymbol, iPeriod, 5, PRICE_CLOSE,MODE_MINUSDI,0);
dDMIminus2=iADX(strSymbol, iPeriod, 5, PRICE_CLOSE,MODE_MINUSDI,1);
 
 
if (dADX1 < dADX2) // ADX falling so dont increase position
{return(0);}
 
// Not falling so must be rising, so...
 
if (dADX1 > 25 && dADX1 < 60) // if above threshold and below reversal risk point
{
if (iDirection == 1 && dDMIplus1 > dDMIplus2 && dDMIminus1 < dDMIminus2 ) // and DMI in buy, approve another lot
{return (1);}
 
if (iDirection == 2 && dDMIminus1 > dDMIminus2 && dDMIplus1 < dDMIplus2 ) // and DMI in sell, approve another lot
{return (1);}
 
}
 
else {return(0);}
 
}