Need help to code

Discussion in 'Strategy Building' started by scrtrade, Aug 9, 2005.

  1. scrtrade

    scrtrade

    Good morning,
    my idea is the following:
    Count the bars since the opening until my indicator1=100.
    If myindicator1=100 the 7th bar then i want to buy if price>highest high of the 1st to 7th bar. And sell if the price< lowest low of the 1st to 7 bar.So It is a very simple and basic idea.

    I tried to code like this:
    VARS:
    count(0),
    countstop(0),
    buysignal(0),
    sellsignal(0);

    If date<>date[1] then begin
    If myindicator1<100 then count=count[1]+1;
    If myindicator1=100 then countstop=countstop[1]+1;
    If countstop=1
    End;
    If countstop=1 then value1=count[1];
    buysignal=highest(high,value1);
    sellsignal=lowest(low,value1);
    If close>buysignal then buy;
    If close<sellsignal the sell;

    If later in the same day myindicator1=100 again, it is not to be calculated. The value1 is fixed once for the all day. I'm just interested for the first time it occurs in the same day.

    Thanking you,
    SCR
     
  2. Remember to reset your counter at the end of the day back to zero for the following day.

    Somethig like...if time=1600 then count=0;
     
  3. scrtrade

    scrtrade

    Thanks for your quick reply,

    I'll try this and let you know the result.

    Bye.
     
  4. scrtrade

    scrtrade

    Unfortunately, it does'nt work.

    I want that the Highest High and Lowest low since the opening, at the moment when
    myindicator=100 for the first time this day since the opening. And this Highest high and the lowest low would be my pivotpoint of the day, even if some times later myindicator=100 again, this does'nt matter and the pivotpoint must not change for the day.
    This pivot point must be calculated every day since the opening of the day untill my indicator=100 for the first time of the day.

    I try this one but it is worst.

    If time>0930 and myindicator<100 then count=count[1]+1;
    If time>0930 and myindicator=100 then count=0;
    If count[1]>0 and count=0 then value1=count[1]
    If time=1600 then count=0;

    Buysignal=highest (high,value1);
    Sellsignal=lowest (low, value1);

    If close>buysignal then buy;
    If close<sellsignal then sell;
    If marketposition=1 and time=1600 then exitlong,
    If marketposition=-1 and time=1600 then exitshort;

    My difficulty is that I try to calculate the value of value1 for each day and I fail!

    Thanks again for your help,
    SCR.
     
  5. scrtrade

    scrtrade

    Up !

    Thanks.
     
  6. What is myindicator1? Why you use it
    Why there is no action after "If countstop=1"?
    If close>buysignal then buy; is also wrong

    Your way of coding is not easy to understand
    for most, or maybe it's me. I think it's good
    idea to put {commentary} for some lines
     
  7. You are using Tradestation, right?
     
  8. scrtrade

    scrtrade

    My indicator is a modified Stochast indicator .

    When the Stoch is >=90 for the first time in the day, say for exemple at 09:47, then in this case, I want that my system give for the "buysignal" the value of the highest high between the opening and the 17th bar, and for the "sellsignal" the lowest low between the opening and the 17ht bar, in the case of a 1min bar chart.
    In this case my "buysignal" for the day would be the highest high of the 17 first bars of the day, and i will buy if
    there is a close>of the buysignal. And sell if close under the "sellsignal".

    Once this two values (buysignal and sellsignal) are fixed, for the first time in a day, they must be the same for the whole day, even if the Stoch indicator is >=90 25 min later. I don't want to take in count the new highest high and the new lowest low.

    The next day at the open, the counter must be at zero and wait that the stoch is >=90 to assign a new value for the highest high and the lowest low. If the stoch is >=90 at the 48th minutes, then my "buysignal" would be the highest high of the 48 first bars of the day and the sellsignal would be the lowest low of the 48 first bars of the day.

    I hope that it's more understandable!

    Thank you .
     
  9. scrtrade

    scrtrade

    For hanseng1,

    yes.
     
  10. WarEagle

    WarEagle Moderator

    scrtrade,

    I am not the most efficient coder, so this can probably be written more concisely, but try this. It is written for TS 2000i, so if you are using TS8 you may need to modify it a bit. Also, I used a simple %R signal for the trigger, you will need to replace it with your indicator. The first section of code is the signal, the second part is an indicator that will plot the buy and sell levels.

    I did not completely understand your rules, so I made some assumptions with the code. The buy and sell levels remain valid all day once they are in place, so if it triggers a buy and then trades back down to the sell level it will reverse and go short. All trades are exited on the close, so there are no stops (other than the reversal on an opposite signal) or profit targets.

    {*****Begin Code*******}
    Inputs: Length(14);
    Vars: Count(0), buySignal(0), sellSignal(0), noMoreSig(false);

    If date<>date[1] then begin
    buySignal = 99999999;
    sellSignal = 0;
    Count = 0;
    Condition1 = false;
    noMoreSig = false;
    End;

    {*****Enter your own indicator trigger here******}
    If PercentR(Length) > 90 then begin
    Condition1 = true;
    End;
    {**********************************}

    If Condition1 = false then begin
    Count = Count + 1;
    End;
    If Condition1 = True and Condition1[1] = False and NoMoreSig = False then begin
    buySignal=Highest(High,Count);
    sellSignal=Lowest(Low,Count);
    noMoreSig = true;
    End;

    If Close > buySignal then Buy;
    If Close < sellSignal then Sell;

    SetExitOnClose;

    {*****End Code*****}


    {*************************************************}

    {*****Indicator Code******}
    Inputs: Length(14);
    Vars: Count(0), buySignal(0), sellSignal(0), noMoreSig(false);

    If date<>date[1] then begin
    buySignal = 99999999;
    sellSignal = 0;
    Count = 0;
    Condition1 = false;
    noMoreSig = false;
    End;

    {*****Enter your own indicator trigger here******}
    If PercentR(Length) > 90 then begin
    Condition1 = true;
    End;
    {**********************************}

    If Condition1 = false then begin
    Count = Count + 1;
    End;
    If Condition1 = True and Condition1[1] = False and NoMoreSig = False then begin
    buySignal=Highest(High,Count);
    sellSignal=Lowest(Low,Count);
    noMoreSig = true;
    End;
    If buySignal = 99999999 then NoPlot(1)
    Else
    Plot1(buySignal, "Buy Above");
    If sellSignal =0 then NoPlot(2)
    Else
    Plot2(sellSignal, "Sell Below");

    {****End Code******}
     
    #10     Aug 9, 2005