NexusFi: Find Your Edge


Home Menu

 





No orders issued part 3


Discussion in EasyLanguage Programming

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




 
Search this Thread

No orders issued part 3

  #1 (permalink)
 arjfca 
Montreal, Canada
 
Experience: Intermediate
Platform: Multicharts
Broker: Interactive Broker
Trading: Forex
Posts: 263 since Sep 2010
Thanks Given: 440
Thanks Received: 91

To enhance clarity I opted to start a new tread

My probles is to code an entry with a stop order. A new position should be created within each bar following a setup.

A) Look for valid setup after the end of a bar. If BarStatus = 2

B) If valid setup, then issue a stop order for the next bar

c) If price of the following bar (after the setup) cross over my target, a new position as to be created.


See the result on the attached picture


Any help greatly appreciated....
Martin
______________________________________________________________________________
Here is my code for the signal
 
Code
[intrabarOrderGeneration = true]
Variables:
BN (0),       //Bar Number
Q   (50000),     // Quantity to trade 
SL   (0),      // Stop Loss
LE   (0),     // Long Entry target
MTH (False),    //MT_Hammer Flag
NB (False),     // New Bar
Goentry (false),    // All is ok, send order to go long
sp (spaces(1));   // Just a regular space for the printing process
{Look for a valid setup after the completion of a bar ( Barstatus = 2)
MT_Hammer = Setup.  True if found
Q:          Quantity.  Modified after each new setup to show individual transaction only
LE:         Long Entry Target.  Price should go over this target within the next bar
SL:         Stop Loss Target.  If in position, This one will be close if price go below this target
GeEntry:    all is OK, Go Send the order to the market
Print:      Just to make sure that I got visualy the same bar
}
If barstatus = 2 then begin
    If MT_Hammer = True then MTH = True else MTH = False;
 
    if MTH Then begin  
           Q= Q + 10000;   
           LE = H + .0002;   
           SL = L - .0002;    
           Goentry = true;    
           Print (BarNumber + 40:0:0, sp, date:0:0, sp, Time:0:0, sp,H:0:5, sp, low:0:5, sp, Q:0:0);  // To make sure that I got visually the same bar        
           Buy next bars Q contracts  at LE stop;
           setstoploss (q * (Range + .0002) * bigpointvalue); 
  GoEntry = False;
     end; 
end;
My Function MT_Hammer
 
Code
{Hammer Fuction Return Hammer =True if all condition is met
Output:  Tail   
                       Hammer (True or False)                   }
Variables:  Length(0),  Body(0),  Tail(0), Nose(0);
Variables:  LBody(0),   HBody(0);
 
LBody = Minlist(Close, Open);     // Slect the bottom price of the body
HBody =Maxlist(close, open);     // Select the upper price of the body
Body = HBody - LBody;
Tail = LBody - Low;        // Tail = Lower part of the body - low of the bar
Nose = High - HBody;      // Nose = uppr par of the bar
Condition1 = Body < Tail;
Condition2 = Nose < Tail;
//condition3 = close >= high -range/3 ;// close in the top 1/3 od the range
If Barstatus  = 2 then begin
 If condition1 and condition2 then MT_Hammer = true else MT_Hammer = False; // The body has to be smaller than the tail by a determined ratio ( RBT) 
 end;

Attached Thumbnails
Click image for larger version

Name:	eratic_Entry.jpg
Views:	227
Size:	96.5 KB
ID:	27067  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
ZombieSqueeze
Platforms and Indicators
How to apply profiles
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #3 (permalink)
Jeff65
Gurnee, IL
 
Posts: 46 since Apr 2010
Thanks Given: 17
Thanks Received: 97


Hello,

I took the liberty of modifying your code where I saw fit. Along the way I had to make some assumptions because what you provided was not a complete system. I assumed you wanted to scale in to your position every time there was a hammer formation. This is controlled within your platform and not within the code. Likewise, you do not need to set intrabar order generation (IOG) to On. This can complicate things and does not affect your system. Stop orders to exit and stop entry orders are placed at the close of a bar for the next bar and are executed in realtime without IOG on. I added a trailing stop just to I could test the program.

I also modified the number of contracts to trade one contract per trade. You can easily change this back to what ever you like.

In the example image you can see the system scales into the position with 1 contract after each hammer. It sets a stop order to enter 2 ticks above the high of the hammer to enter. A hard stop is activated for the order bar only. Then a trailing stop is used for all other bars.



Let me know if you have questions. This was built with TradeStation 8.8

 
Code
{
Hammer Fuction Return Hammer =True if all condition is met
Output:  Tail   
Hammer (True or False)
}
Variables:  Length(0),  Body(0),  Tail(0), Nose(0);
Variables:  LBody(0),   HBody(0);
 
LBody = Minlist(Close, Open); // Slect the bottom price of the body
HBody = Maxlist(close, open); // Select the upper price of the body
Body  = HBody - LBody;
Tail  = LBody - Low;          // Tail = Lower part of the body - low of the bar
Nose  = High - HBody;         // Nose = uppr par of the bar

Condition1 = Body < Tail;
Condition2 = Nose < Tail;

If ( condition1 ) And ( condition2 ) Then 
   MT_Hammer = true 
Else 
    MT_Hammer = False; // The body has to be smaller than the tail by a determined ratio ( RBT)
 
Code
//[intrabarOrderGeneration = true]
// IOG does not need to be used to have orders filled intrabar. IOG is used to evaluate your strategy upon every tick.
// It appears to me you are evaluating the close of a 15-minute bar and placing resting orders for next bar, thus
// IOG is not needed.

Variables:
   OneTickValue$(iff(GetExchangeName="FOREX", MinMove/PriceScale*BigPointValue*100000, MinMove/PriceScale*BigPointValue)),
   OneTickValue(iff(GetExchangeName="FOREX", MinMove/PriceScale*100000, MinMove/PriceScale)),
   
   Stop$(0),
 
   BN       (0),           // Bar Number
   Q        (1),           // Quantity to trade 
   SL       (0),           // Stop Loss
   LE       (0),           // Long Entry target
   MTH      (false),       // MT_Hammer Flag
   NB       (false),       // New Bar
   Goentry  (false),       // All is ok, send order to go long
   sp       (spaces(1));   // Just a regular space for the printing process
   
   
{Look for a valid setup after the completion of a bar ( Barstatus = 2)
MT_Hammer = Setup.  True if found
Q:          Quantity.  Modified after each new setup to show individual transaction only
LE:         Long Entry Target.  Price should go over this target within the next bar
SL:         Stop Loss Target.  If in position, This one will be close if price go below this target
GeEntry:    all is OK, Go Send the order to the market
Print:      Just to make sure that I got visualy the same bar
}

Once SetStopPosition; 

If ( MT_Hammer ) Then
Begin

   //MTH = true;
   //Goentry = true;
   
   //Q  = Q + 1;
   LE = H + 2*OneTickValue;   
   SL = L - 2*OneTickValue;    
   
   // To make sure that I got visually the same bar        
   Print (BarNumber + 40:0:0, sp, date:0:0, sp, Time:0:0, sp,H:0:5, sp, L:0:5, sp, Q:0:0);  

   // We do not want to place a buy order when range=0
   // Check for OnTickValue > 0 to ensure we do not get a division-by-zero error.
   
   If ( Range > 0 ) And ( OneTickValue > 0 ) Then 
   Begin
      Buy("LE") Q contracts next bar at LE stop; 
      Stop$ = ( (range)/OneTickValue*OneTickValue$ );
      setstoploss ( Stop$ );
   End;
   
   //GoEntry = false;
   
End;

// Trailing Exit for Longs
// Trailing stop handles trade after inital purchase.

If ( MarketPosition = 1 ) Then
   Sell("TSL") next bar at Lowest(Low,3) stop;

Reply With Quote
Thanked by:
  #4 (permalink)
 arjfca 
Montreal, Canada
 
Experience: Intermediate
Platform: Multicharts
Broker: Interactive Broker
Trading: Forex
Posts: 263 since Sep 2010
Thanks Given: 440
Thanks Received: 91

Hello Jeff

Many thanks again for your input. I always learn and progress with your inputs.

You where right , this exercise was not at all a trading concept, Only to described my problems to put entry on the system. I was focussing only on the technicality of orders process, nothing from the stop loss. (insane, i know, but that was the my goal. )

For about 1 hour, I chat with Dave M. from Multicharts. Using the remote toll he found that I had

IntraBarOrderGeneration = True with Bar Magnifier = 1 tick enabled at the same time. Together they mess-up the calculation and orders wheres not put or put later. That was the main problem.

Now, I could go on with my real sytem. and yes, the main part is the stop management.

Best wish of success and happiness for 2011 to you and Big Mike forum members.


Martin

Started this thread Reply With Quote
  #5 (permalink)
Jeff65
Gurnee, IL
 
Posts: 46 since Apr 2010
Thanks Given: 17
Thanks Received: 97

You're welcome. Glad to hear things are progressing.



arjfca View Post
Hello Jeff

Many thanks again for your input. I always learn and progress with your inputs.

You where right , this exercise was not at all a trading concept, Only to described my problems to put entry on the system. I was focussing only on the technicality of orders process, nothing from the stop loss. (insane, i know, but that was the my goal. )

For about 1 hour, I chat with Dave M. from Multicharts. Using the remote toll he found that I had

IntraBarOrderGeneration = True with Bar Magnifier = 1 tick enabled at the same time. Together they mess-up the calculation and orders wheres not put or put later. That was the main problem.

Now, I could go on with my real sytem. and yes, the main part is the stop management.

Best wish of success and happiness for 2011 to you and Big Mike forum members.


Martin


Reply With Quote




Last Updated on December 19, 2010


© 2024 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 - Privacy Policy - Downloads - Top
no new posts