You didn't post a topic yet. Let us show you how to make your first topic and upload your favorite forex robot. Guide me

Skip to forum content

Log-In or Register to get unlimited download access of Forex Robots!

Login with Facebook!

Login with Facebook

Login with Username and Password!

     Username:       Password:  Login

Register  |  Forgot Password?

 

 

The latest topics with attached files (Forex robots, Forex Indicators, etc..)

Forums in this category with details of Replies, Views, last post

Trendline Idikator

by an84ma

very easy ea

by an84ma

PZ Harmonic Scanner

by Adeyemi Damilare Abdul Afeez


[ Closed ]

Pages 1

You must login or register to post a reply

RSS

Posts: 2
Please rate this topic
Current rating: 0
Votes: 0

Embed topic to your site

PSAR

Topic: PSAR

//+------------------------------------------------------------------+
//|                                                 EA-PSAR_v1-0.mq4 |
//|                                                    Luca Spinello |
//|                                
//+------------------------------------------------------------------+

#property copyright     "Luca Spinello - mql4tradingautomation.com"
#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

//Functional variables
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

//Functional variables to determine prices
double MinSL;
double MaxSL;
double TP;
double SL;
double Spread;
int Slip; 


//Variable initialization function
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;
}


//Check if orders can be submitted
void CheckCanOrder(){            
   if( Bars<MinBars ){
      Print("INFO - Not enough Bars to trade");
      CanOrder=false;
   }
   OrdersOpen();
   return;
}


//Check if there are open orders and what type
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;
}


//Close all the orders of a specific type and current symbol
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("ERROR - CLOSE - error closing order ",Ticket," return error: ",GetLastError());
         }
      }
   }
   return;
}


//Open new order of a given type
void OpenNew(int Command){
   RefreshRates();
   double OpenPrice=0;
   double SLPrice;
   double TPPrice;
   if(Command==OP_BUY){
      OpenPrice=Ask;
      SLPrice=OpenPrice-SL;
      TPPrice=OpenPrice+TP;
   }
   if(Command==OP_SELL){
      OpenPrice=Bid;
      SLPrice=OpenPrice+SL;
      TPPrice=OpenPrice-TP;
   }
   for(int i=1; i<OrderOpRetry; i++){
      int res=OrderSend(Symbol(),Command,LotSize,OpenPrice,Slip,NormalizeDouble(SLPrice,Digits),NormalizeDouble(TPPrice,Digits),"",MagicNumber,0,Green);
      if(res){
         Print("TRADE - NEW - Order ",res," submitted: Command ",Command," Volume ",LotSize," Open ",OpenPrice," Slippage ",Slip," Stop ",SLPrice," Take ",TPPrice);
         break;
      }
      else Print("ERROR - NEW - error sending order, return error: ",GetLastError());
   }
   return;
}


//Technical analysis of the indicators
bool CrossToOpenBuy=false;
bool CrossToOpenSell=false;


void CheckPSARCross(){
   CrossToOpenBuy=false;
   CrossToOpenSell=false;
   double PSARCurr=iSAR(Symbol(),0,PSARStep,PSARMaxStep,0);
   double PSARPrev=iSAR(Symbol(),0,PSARStep,PSARMaxStep,1);
   if(PSARCurr<Close[0] && PSARPrev>Close[1]){
      CrossToOpenBuy=true;
   }
   if(PSARCurr>Close[0] && PSARPrev<Close[1]){
      CrossToOpenSell=true;
   }
}


//Trailing Stop with PSAR
void UpdatePositions(){

   //Scan the open orders backwards
   for(int i=OrdersTotal()-1; i>=0; i--){
   
      //Select the order, if not selected print the error and continue with the next index
      if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) {
         Print("ERROR - Unable to select the order - ",GetLastError());
         continue;
      } 
      
      //Check if the order can be modified matching the criteria, if criteria not matched skip to the next
      if(OrderSymbol()!=Symbol()) continue;
      if(OrderMagicNumber()!=MagicNumber) continue;
      
      //Prepare the prices
      double TakeProfitPrice=OrderTakeProfit();
      double StopLossPrice=OrderStopLoss();
      double OpenPrice=OrderOpenPrice();
      double NewStopLossPrice=StopLossPrice;
      double NewTakeProfitPrice=TakeProfitPrice;
      
      //PSAR Value of the current symbol, current time frame , PSARStep, PSARMaxStep, previous candle
      double PSARPrice=iSAR(Symbol(),0,PSARStep,PSARMaxStep,1);
      
      //Get updated prices and calculate the new Stop Loss and Take Profit levels, these depends on the type of order
      RefreshRates();
      if(OrderType()==OP_BUY){
         if(PSARPrice>StopLossPrice && PSARPrice<Close[1] && PSARPrice<TakeProfitPrice){
            NewStopLossPrice=NormalizeDouble(PSARPrice,Digits);
         }
      } 
      if(OrderType()==OP_SELL){
         if(PSARPrice<StopLossPrice && PSARPrice>Close[1] && PSARPrice>TakeProfitPrice){
            NewStopLossPrice=NormalizeDouble(PSARPrice,Digits);
         }
      }
      
      //If the new Stop Loss and Take Profit Levels are different from the previous then I try to update the order
      if(NewStopLossPrice!=StopLossPrice){
         Print("Modifying order ",OrderTicket()," Open Price ",OpenPrice," New Stop Loss ",NewStopLossPrice," New Take Profit ",NewTakeProfitPrice);
         if(OrderModify(OrderTicket(),OpenPrice,NewStopLossPrice,NewTakeProfitPrice,0,Yellow)){
            Print("Order modified");
         }
         else{
            Print("Order failed to update with error - ",GetLastError());
         }      
      
      }

   
   }
}




//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   //Calling initialization, checks and technical analysis
   Initialize();
   CheckCanOrder();
   UpdatePositions();
   CheckPSARCross();
   //Check of Entry/Exit signal with operations to perform
   if(CrossToOpenBuy){
      CloseAll(OP_SELL);
      if(CanOpenBuy && CanOrder) OpenNew(OP_BUY);
   }
   if(CrossToOpenSell){
      CloseAll(OP_BUY);
      if(CanOpenSell && CanOrder) OpenNew(OP_SELL);
   }
  }
//+------------------------------------------------------------------+

Post's attachments

EA-PSAR_v1-0.ex4 15.2 kb, 36 downloads since 2017-12-13 

Share

Thanked for the post: jozmik

Re: PSAR

li will check this, thank you very much, i have some eas, i will post here, thank you for all information, see you later, thank you very much

Share

Posts: 2

Pages 1

You must login or register to post a reply

Last Posts

  • 16/08: The assar v8 of bader alharbi is real?
  • 16/08: My Favorit EA Lifechanger
  • 16/08: credible broker
  • 16/08: Assar Elite Pro Forex Scalper V10
  • 16/08: Assar v8 1m eurusd the best forex my test ok good
  • 16/08: HIGH DRAWDOWN AND CONTINIOUS LOSS MAKING ROBOT
  • 16/08: Ubat 5.0
  • 16/08: Scalping EA Use on H1
  • 16/08: Selection of broker
  • 14/08: Trendline Idikator
  • 14/08: very easy ea
  • 14/08: BBMA indicators 1
  • 14/08: UPDATE: This robot now makes huge money! $24,512 profit in 10 days!
  • 13/08: Virtual Earning Platforms
  • 13/08: IceFX TraderAgent pro
  • 12/08: Trading as per rule
  • 12/08: PZ Harmonic Scanner
  • 12/08: HNAVHelios + V2.04 any member have this EA?
  • 11/08: This robot made me over $20,000.
  • 11/08: supertrend ea basic
  • 11/08: Forex Tips EA
  • 11/08: Very interesting free EA
  • 11/08: face great adversity
  • 11/08: PRO VSA EA
  • 10/08: Good broker or scam broker?
  • 10/08: Arbitrage Forex Software
  • 10/08: Hobbit v7
  • 10/08: Candle Stick Trading Bible by Homma
  • 10/08: Maintain systematic manner
  • 08/08: Mupa EA
  • 08/08: Assar V11
  • 08/08: What is the reason to select forex?
  • 06/08: forex alien force indicator
  • 06/08: EA scalpin 2018
  • 06/08: Modify
  • Hot Topics

  • ASSAR v8 (1042)
  • Scalper_v5 (free) (720)
  • A highly profitable Ea (465)
  • FX Magic Robot - Verified Live Working 3/13/17 (458)
  • 2000 pips daily (450)
  • ASSAR V9 (Trend Breakout Edition) 2017 Expert Advisor (417)
  • spartan bolt V6 (414)
  • Assar_03_EA (389)
  • ASSARV11 [EXCLUSIVE] ACTIVE MEMBERS ONLY! (274)
  • Forex Earth Robot (249)
  • Trade-Arbitrage EA (248)
  • xmt scalper (227)
  • Forex Math EA free for Mt4 (180)
  • Super Signal Scalping Profit Statement (178)
  • Rabbit3 £100 start Zero to Hero Updated EA (167)
  • Fracture 7.4.0 (156)
  • high profit EA (151)
  • SCALPER PALING JOSS EA is a Holy Grail (150)
  • New to forex? (148)
  • Ilan Expert Advisor for Metatrader 4 (136)
  • EA SmartAssTrade. (133)
  • Monster Profit Forex Robot (123)
  • WayGrow EA 1.7 (110)
  • scalperstarkpro downoad free (price 90 dollars) (92)
  • FX Magic Robot (91)
  • IceFX TraderAgent Pro EA v2.5.1 (86)
  • Profitable GBPJPY EA (true results) (85)
  • Unbelievable EA (75)
  • Hedge Expert Advisor (63)
  • 100 pips profits trading (63)
  • Good EA 2017. Free !!! (63)
  • Magic Fx Formula indicator-V2 (61)
  • Best Indicator That No Repaint!!! (61)
  • BAR EA V5.1 (60)
  • hello (60)

  •  

    NOTE: Hacked or illegal versions of copyrighted Forex robots are highly prohibited on MT4talk.com. If you upload any illegal version of any copyrighted Forex robot, your forum account will be banned. No exceptions.

    Forum statistics

    • Total number of registered users: 21,311
    • Newest registered user: jchez2k
    • Total number of topics: 11,153
    • Total number of posts: 36,651

    Online users: 1,741 guests, 167 Members:

    1moretrader, 777legrand, 786lands, a.cavalca, Abhyuday Jetley, abs072, admin, akulah08, algomatru, Amin Fairul, Amit Hira, an84ma, Andrea Bertini, Andrew Tay, AnthonyT, Anurag Diwakar, axel7969, b1836753, Bandeauman Gjc RG, bbc7716, bbtt181, bertoneri_dubai, bestkid321, bjerkmar, Bobby Hm, BoZorgmehr MirMotahari, c4s3linux, calimocho5, cbeert, cesardefez, CFORNI99, Chiloane Clement, chrystalrico, cindar, cmarcelle7, d.kultida, Darshana Samaraweera, demer, Dino Lampa, Donnie Drajat, East Wang, edsonkrk@gmail.com, eduardo_147_147, elizarmakhobatlou, Ente26, erikrooze, FFFOOO, Fred13, galihridha, Gearofwar, gelienm, gerard.torrents, Gizmo79, gntgnt8, guillermohoffmann, hhh45, Horacio, HPATEL, Hyunki Choi, Inconito75, Ingmar Näks, Ir Zulkifli AbdRahman, jamesjijojo, jayme9111, jchez2k, Joe0013, John Ibrahim Cuadra, Jordan Georgiev, Jordan Pritchett, Jose Ferreira Nascimento, jozmik, juanvanni9917, KAPILDEV5153, kepospj, kerim_0_5, Khalid AL Saeed, KieCong, Kojo Bame, kpong, Lalin Perera, lehisokoh, Léo Sousa, littlebee722, lolsun, Lucas Alonso, luis.bloch, m1ch4lryb4, machamdhg, machs_nochmal, MagerMoLcH4, Mahmood Sharif, martinesleonardo, matramfo, matubetube71, maxheadroom, message, Michel Massina, miguefx, Miguel Font Rosselló, mihai.dorosin, msyahirs, mthobela, mukeshjoe30, muratoncupatent, mysticalmillette, m_peyman2000, n05p43, n111, naledindelane, Nguyễn Tuấn Anh, nguyentrieuit, nicholasariston84, Ntsikasikhakhane6, ogrizek, omolewayeolagd1997, Otto Lovasz, pauljfitzpatrick, pblam, pigman50, pirro, pky2j2000, Prateek Khare, pravin.todkar31, Priya Ashok, Przemyslaw, ptctodo, rad1958, Raja Ponnusamy, Ronny Haro, Rubens Souza, rwmngt, Sameh Sawa, Santosh Kokadiya, sasastephe, seenuchennai, Shakeel Urrehman, soerenpalm, Sohn Jungman, srca7354, Sukarman B. Lasmo, szilan007, tahiri, Takeme Toyoure Lazyboy, Tejas Parekh, tejaybabs, Thobib Herba Qaseh, Thomas Perdana, Tiwa Komkong, Trần Quốc Việt, ueuktfd, unreal-1980, viajrdz19, Victoriano, Vonani Bafanah Shibambu, Vylance Tiong, Weallant Alphonsus, webuser14, why, wibowooo, Will Masha, Wllie Bester, YM, Yudix Ajuzz, Zdeněk Dvořák, ZHOUBAO, zombi, แมงเม่า บินเข้ากองไฟ

     


    Copyright MT4talk.com Forum Rules - Privacy Policy.