NexusFi: Find Your Edge


Home Menu

 





Open trade and closing trade on reverse signal


Discussion in Platforms and Indicators

Updated
    1. trending_up 2,562 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
ryangillespie's Avatar
 ryangillespie 
london, England
 
Experience: Intermediate
Platform: Ninjatrader
Trading: CL, ES
Posts: 41 since Nov 2011
Thanks Given: 10
Thanks Received: 2

I am trying to write an EA using an indicator with icustom.

How can I get the EA to close an open trade when an alternate signal is fired. Also how can I send a market order on the next bar when the signal has fired.

extern double downtrend;
extern double uptrend;
input double lots=1;



int start()


{

int downtrend = downtrend=iCustom(NULL,0,"DayTrading",2,0);
int uptrend = uptrend=iCustom(NULL,0,"DayTrading",1,0);


if(downtrend)
{
bool ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,"DayTrading",16384,0,Red);
}
else if(uptrend)
{
ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,"DayTrading",16384,0,Green);
}
}



Thanks


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
[WTS] ATAS Lifetime ULTRA license – EU buyers only – …
Platforms and Indicators
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
My Rant with AMP Futures
Trading Reviews and Vendors
Building a free browser DOM/SMC simulator - need some ad …
Platforms and Indicators
Bitcoin’s 2022 low, 2025 high and 2026 low so far arou …
Cryptocurrency
 
  #3 (permalink)
 
ryangillespie's Avatar
 ryangillespie 
london, England
 
Experience: Intermediate
Platform: Ninjatrader
Trading: CL, ES
Posts: 41 since Nov 2011
Thanks Given: 10
Thanks Received: 2


 
Code
                            
extern double Lots = 2;

extern double Slippage = 2.0;
extern int    MagicNr=9502;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()



 { 
  
double ArrowUp, ArrowDown;
  static 
int iBuyTicket=-1;
  static 
int iSellTicket=-1;
  static 
datetime tCurTime;
 
  
  
// Get Supersignal state
  
ArrowUp = iCustom(NULL,0,"PZ_DayTrading",1,0);
  
ArrowDown = iCustom(NULL,0,"PZ_DayTrading",2,0);
  
  
// Open orders on new bar only
  
if (tCurTime != Time[0]) {
    
tCurTime=Time[0];
    
    
// Open Buy order if previous bar has arrow up signal
    
if  (ArrowUp!=1 && iBuyTicket<0) 
      
iBuyTicket=OrderSend(Symbol(),OP_BUY,Lots, Ask, Slippage, 0, 0, 
                
"DayTrade", MagicNr, NULL, LimeGreen);    
    
    
// Open Sell order if previous bar has arrow up signal
    
else if  (ArrowDown!=2 && iSellTicket<0) {
      
iSellTicket=OrderSend(Symbol(),OP_SELL,Lots, Bid, Slippage, 0, 0,
                
"DayTrade", MagicNr, NULL, LimeGreen);    
    }
  } 
Now the EA opens various trades, it should only open a single position the bar after the indicator has signalled an arrow.

Also how do I close an open position when an opposite signal occurs.

Thank you all


Started this thread Reply With Quote




Last Updated on July 8, 2015


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts