Buy Next Bar or Next Tick

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

Buy Next Bar or Next Tick

Postby arjfca » 16 Dec 2010

Hello

Buy Next Bar is a Buy Next tick.... Meaning , after a buy stop order is issued, it is valid only for the next tick (bar). It should be valid for the entire 15 minutes bar. Actually, the entry is done only if the first tick after the order, fulfilled the targeted stop price (LE).

Code: Select all

[intrabarOrderGeneration = true]

   if marketposition <> 1 then begin
   If Goentry = True  then Begin
      Buy ("Long1") next bars Q contracts  at LE stop;
          setstoploss (q * (Range + .0002) * bigpointvalue);
             End;
 end;


Only the tick placed immediatly after the targeted price will create a long entry.

How could I have my stop order entry valid for a full 15 minutes bar length?

Martin

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 485 times

Re: Buy Next Bar or Next Tick

Postby Dave Masalov » 16 Dec 2010

Dear Martin,

Please send us the full script. It is hard to say anything looking at this piece of code. The order will stay active for this bar as long as the condition Goentry = True; is met. From this piece of code we cannot see when it goes to false.

arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

Re: Buy Next Bar or Next Tick

Postby arjfca » 16 Dec 2010

Hello Dave

Here a resume of my code. MSignal could be any singnal entry

Hope my explanation is OK

Code: Select all

[intrabarOrderGeneration = true]
Variables:
 BN (0),
 Q   (0), 
SL   (0),
LE   (0),
NB (False),
intrabarpersist Goentry (false);

if MB <> BarNumber   then begin
   NB = True;
   MB = Barnumber;
end;
 

   If barstatus = 2 then begin    // Make sure the bar as terminated
    if  MSignal then begin  // Look for a valid signal.  If found compute the entry and exit
           Q=125000;
           LE = H + .0002;
           SL = L - .0002;
           Goentry = true;    // All ok to send the order         
     end;
  end;
 
     // Put an order that should be valid for the entire bar (15 minutes or whatever scale) after the signal
   
    // This section here cause problem.   Stop Entry order look to be valid only for the next Tick after
    //  the order was sent.
 If Goentry = True  Then begin      // Yes, I got the OK to send order
   Buy ("Long1") next bars QTY contracts  at LongEntry stop;
              setstoploss (q * (Range + .0002) * bigpointvalue);
       end;

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 485 times

Re: Buy Next Bar or Next Tick

Postby Dave Masalov » 16 Dec 2010

Please tell us if LongEntry is fixed price or can it change within the bar where the order is generated? If it is fixed, then one order should be generated and stay at the broker not only before, but also after the end of the bar. We still cannot see where GoEntry is reset.

arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

Re: Buy Next Bar or Next Tick

Postby arjfca » 16 Dec 2010

Dave,
LongEntry is a variable
This work is only a test for me, not a valid signal. That the reason for the stop not being moved.
I want to learn how to code for an entry that respond to my criterias

A stop entry on the following bar after a signal bar. Order to be canceled if target not reached.



Sligtly modified code. Quantity to trade modified after each new signal to better show my problem

Now I got duplicate entry and entry done after the order should had been canceled


Code: Select all

[intrabarOrderGeneration = true]
Variables:
BN (0),
Q   (10000), 
SL   (0),
LE   (0),
NB (False),
intrabarpersist Goentry (false);

if BN <> BarNumber   then begin
   NB = True;
   BN = Barnumber;
end;


   If barstatus = 2 then begin    // Make sure the bar as terminated
    if TSignal then begin  // Look for a valid signal.  If found compute the entry and exit
           Q=Q + 10000;
           LE = H + .0002;
           SL = L - .0002;
           Goentry = true;    // All ok to send the order         
     end;
  end;

     // Put an order that should be valid for the entire bar (15 minutes or whatever scale) after the signal
   
    // This section here cause problem.   Stop Entry order look to be valid only for the next Tick after
    //  the order was sent.
If Goentry = True  Then begin      // Yes, I got the OK to send order
   Buy ("Long1") next bars Q contracts  at LE stop;
              setstoploss (q * (Range + .0002) * bigpointvalue);
 end;
Attachments
eratic_Entry.jpg
Eratic entry
eratic_Entry.jpg (59.39 KiB) Viewed 164 times

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 485 times

Re: Buy Next Bar or Next Tick

Postby Dave Masalov » 17 Dec 2010

Dear Martin,

It is hard to suggest something as this is not the full code. It cannot be compiled.

What do you do to cancel the order? You wrote: Order should had been cancelled. Why?

Condition for the order is still met on the next bar and on the one after etc. It is never reset to false.


Return to “MultiCharts”