NexusFi: Find Your Edge


Home Menu

 





RISTRICTING ENTRY LIMIT ORDER TO ONE BAR ONLY


Discussion in MultiCharts

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




 
Search this Thread
  #1 (permalink)
Tiforp
Cambridge, UK
 
Posts: 5 since Jun 2010
Thanks Given: 1
Thanks Received: 1

I am frustrated when unfilled limit or stop entry orders carry on to the next bar. It does not happen to often, but is quite troublesome when it does.

Therefore, I shall be very appreciative for programming help to ensure via strategy code so any unfilled entry position stop order / limit order is cancelled at the end of day, or bar, and does not carry to the next session.

Below are two entry instructions examples:
  1. sellshort next bar at open next bar + .05 Limit;
  2. if condition1 = true then buy next bar at currentbid limit;

Thank you in advance.

Tiforp


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
GDP Day: The First Economic Reckoning -- Pahlavi at 6.55 …
Prediction Markets & Event Contracts
El Clasico Draws $9.2M in Prediction Market Action -- Bi …
Prediction Markets & Event Contracts
Beijing Summit Closes: Xi Pledges Hormuz Help -- $1.14B …
Prediction Markets & Event Contracts
Kalshi Sets $4.13B All-Time Weekly Record as Polymarket …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
16 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
2 thanks
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

Tiforp,

Multicharts will keep an order alive as along as the condition that triggered the order is valid. You can use this by adding a condition to your order that you set to false X bars after you set it to true. You could for example store the bar number when you want to issue the order in a variable (let's call it "longOrderBar"). Then check for the current bar being equal to this variable before you issue your order - this wouldn't require resetting the condition,
as it becomes false on subsequent bars.

 
Code
if CurrentBar = longOrderBar then
 SellShort...
Regards,

ABCTG


Follow me on X Reply With Quote
Thanked by:
  #3 (permalink)
Tiforp
Cambridge, UK
 
Posts: 5 since Jun 2010
Thanks Given: 1
Thanks Received: 1



ABCTG View Post
Tiforp,

Multicharts will keep an order alive as along as the condition that triggered the order is valid. You can use this by adding a condition to your order that you set to false X bars after you set it to true. You could for example store the bar number when you want to issue the order in a variable (let's call it "longOrderBar"). Then check for the current bar being equal to this variable before you issue your order - this wouldn't require resetting the condition,
as it becomes false on subsequent bars.

 
Code
if CurrentBar = longOrderBar then
 SellShort...
Regards,

ABCTG

ABCTG,

Thank you for your help. Verpflichtet.


Reply With Quote
Thanked by:
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

Tiforp,

you are welcome.

Regards,

ABCTG


Follow me on X Reply With Quote
  #5 (permalink)
Tiforp
Cambridge, UK
 
Posts: 5 since Jun 2010
Thanks Given: 1
Thanks Received: 1

ABCTG,

After you kind reply I did try to write a working code, but obviously have missed certain key elements because it complies but does not execute any trades. Most probably I have missed out correctly completing the “CurrentBar” and “longOrderBar”:

1. CurrentBar[ StdFunction ] : Return(Numeric)
2. longOrderBar[ Variable ] : NumericSimple

It appears simple enough, but I cannot seem to make any progress!

My full code is included. Any help once again shall be greatly appreciate.

Thank you.

 
Code
Inputs: 
MyContracts (1          { Indicate number of contracts to trade}),
StartTime   (900       { Designate valid intraday start-trading time}),
NumBarsP    (5          { Number of bars since entry});

Variables:
longOrderBar (0         { To ensure any unfilled entry order is not carried to the next bar });
     
If ( Time = StartTime )and CurrentBar[0] = longOrderBar Then  
     Begin
          SellShort("")  MyContracts Contracts next bar at CurrentAsk Limit;
     End;
     
 { --- Exit at N bars since entry --- }
      
 If ( NumBarsP > 0 ) Then
     Begin
          If marketposition = -1 and BarsSinceEntry >= NumBarsP Then Buytocover("Stop") MyContracts contracts next bar at Market;      
     End;


Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

Tiforp,

you can use the print reserved word, to check the values of the variables in your code on every bar.

As I wrote above "You could for example store the bar number when you want to issue the order in a variable (let's call it "longOrderBar")." Your code doesn't store the bar number when you want to issue the order. That's what you will have to do first, before checking for CurrentBar = longOrderBar. Otherwise longOrderBar will have a value of 0. CurrentBar on the other hand will always be greater than 0 and in turn your condition will never be true and you would see no trade entries.

From looking at your code and under the condition that you are on time based intraday charts, checking for "( Time = StartTime )" should be true only once per day. Which would already limit the order to one bar.

Regards,

ABCTG


Follow me on X Reply With Quote




Last Updated on February 5, 2018


© 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