FXPC
I thought the standard PSAR closed up near the end of the trend anyway?
This will get you started though
//+------------------------------------------------------------------+ //| Move Stops To PSAR Ver 1.1.mq4 | //| BD | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, SelectFX" #property link "http://www.selectfx.net" extern int MagicNumber=989; extern double PSARStep = 0.02; extern double PSARMax = 0.2; extern bool CheckEveryTick = true; string strSymbol; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- strSymbol = Symbol(); if ((!CheckEveryTick) && (Volume[0]==1)) // Go for it on first tick only { MoveStopsToPSAR(MagicNumber, 1); return(0); } if(CheckEveryTick) MoveStopsToPSAR(MagicNumber, 0); // Check for Stop move every tick //---- return(0); } //+------------------------------------------------------------------+ void MoveStopsToPSAR(int iMN, int iShift) { int icnt, itotal; double ActiveSAR; double Close_1 = Close[iShift]; ActiveSAR = iSAR(NULL,0,PSARStep,PSARMax,iShift); itotal=OrdersTotal(); for(icnt=0;icnt<itotal;icnt++) { // order loop boundary OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES); // check for opened position, symbol & MagicNumber if(OrderType()==OP_SELL && OrderSymbol()==strSymbol && OrderMagicNumber()==iMN) { if ((ActiveSAR > Close_1) && (ActiveSAR!=OrderStopLoss())) OrderModify(OrderTicket(),OrderOpenPrice(),ActiveSAR,OrderTakeProfit(),0,Yellow); } if(OrderType()==OP_BUY && OrderSymbol()==strSymbol && OrderMagicNumber()==iMN) { if ((ActiveSAR < Close_1) && (ActiveSAR!=OrderStopLoss())) OrderModify(OrderTicket(),OrderOpenPrice(),ActiveSAR,OrderTakeProfit(),0,White); } } // order loop boundary return(0); }
FWIW
-BB-
FXPC
I thought the standard PSAR closed up near the end of the trend anyway?
This will get you started though
FWIW
-BB
Thanks BB, that is true about the PSAR closing in near end of trend but I want it to close in to protect my profits not gauge trend, I use other indicators for strength of trend. I'm a young trader getting involved in coding and am fascinated by the MQL4 style and coding in Tradestation, do you have sort of literature that you particularly like for fundamental code developing and basic code structuring?
Thanks again for your help, my next step is to plug in the incremental PSARS.
FXPC
FXPC
> I want it to close in to protect my profits
If you are getting closer than PSAR, you are likely to be flipped out of the trade anyway
I'd suggest a use of three small orders that are closed at different stages near the end of a trend, controlled by e.g. CCI diverging from price action
It can be non-productive to try & pick tops or bottoms to the pip!
FWIW
-BB-

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello All:
I'm attempting to code my stops so that if profit (in pips) is between 30 & 60, the stop should be based on a PSAR with a step of .03. If profit (again, in pips) is between 60 & 90, the stop should be at the PSAR with a step of .02. Finally, if Profit is between 90 and 120, the stop should be at a PSAR of .01. What I have is below:
if(OrderType() == OP_BUY)
{
if (OrderStopLoss() != PSAR1)
if( Ask > OrderOpenPrice() + (30* Point) && Ask < OrderOpenPrice() + (60* Point) && Ask > PSAR1)
{
OrderModify(OrderTicket(),OrderOpenPrice(),PSAR1, OrderTakeProfit(),0,Blue);
}
if(OrderStopLoss() != PSAR2)
if(Ask > OrderOpenPrice() + (60*Point) && Ask < OrderOpenPrice() + (90* Point) && Ask > PSAR2)
{
OrderModify(OrderTicket(),OrderOpenPrice(),PSAR2, OrderTakeProfit(),0,Blue);
}
if(OrderStopLoss()!= PSAR3)
if(Ask > OrderOpenPrice() + (90*Point) && Ask < OrderOpenPrice() + (120* Point) && Ask > PSAR3)
{
OrderModify(OrderTicket(),OrderOpenPrice(),PSAR3, OrderTakeProfit(),0,Blue);
}
PSAR1 = iSAR(NULL, 0, .03, .2, 0);
PSAR2 = iSAR(NULL, 0, .02, .2, 0);
PSAR3 = iSAR(NULL, 0, .01, .2, 0);
The strategy is derived from Charles Lebeau's strategy of using tighter stops as profitability increases.
Thanks for any help,
Pat