Can no one guide me with this script? Please advice! --- In [email protected], "iliagold1" <[EMAIL PROTECTED]> wrote: > > Hello, > > It did not work, let me try to explain what we are actually trying > to do. > > We would like to optimize a formula on 30 days of the crude oil > future and we would like to trade only between 14:00 and 18:00. The > problem we encountered is that if a trade is not sold before 18:00, > it will stay overnight until next day. That is not what we want > because it is far too risky! Therefore, when a trade is still open > after 18:00, it should have a have a trailing-stop applied to it, > with a maximum loss of 20 cents. > > Exmaple of a trailing-stop: > > At 17:44 the system buy's one contract at $68.00, at 18:00 it is > still not sold and the price is at $67.70, at 18:01 a trailing- stop > is applied with 20 cents max. loss (max loss is if price goes to > goes to $67.50). > The price goes to 68.10, and the contract is still not sold, but the > trailing stop is moved from $67.50 to $67.90. Then the price falls > to 67.90 and the stop order is executed and the contract is sold > (with a loss of 10 cents) > > I hope this is clear that somebody can help me code this stop. I > have asked the support of AmiBroker but they did not reply in a few > days and we are kind of in a hurry. > > > --- In [email protected], Graham <kavemanperth@> wrote: > > > > you cannot use applystop like this > > try this, it might work > > > > Sell = Cross( Signal( fa, sa, sig ), MACD( fa, sa ) ) > > or cross( valuewhen( timecondition2, C-0.1 ), L ); > > > > -- > > Cheers > > Graham > > AB-Write >< Professional AFL Writing Service > > Yes, I write AFL code to your requirements > > http://www.aflwriting.com > > > > > > On 09/05/07, iliagold1 <iliagold1@> wrote: > > > Hello all, > > > > > > I would like to add a trailing stop after the last order of the > day > > > of 10 cents, how would I put that in the formula? > > > > > > I tried something like this but it does not work, please help. > > > > > > tn2 = TimeNum(); > > > timecondition2 = tn2 >= 180001; > > > > > > if( LastValue( Buy AND timecondition2 ) ) > > > > > > { > > > ApplyStop( 2, 2, 1, 100, False, 1 ); > > > } > > > > > > > > > ---------- > > > > > > Bellow is the full formula: > > > > > > /* variable = optimize( "Description", default, min, max, step ) > */ > > > fa = Optimize( "MACD Fast", 661, 1, 1000, 10 ); > > > sa = Optimize("MACD Slow", 221, 1, 400, 10 ); > > > sig = Optimize( "Signal average", 171, 1, 200, 10 ); > > > > > > tn = TimeNum(); > > > timecondition = tn >= 140000 AND tn < 180000; > > > > > > tn2 = TimeNum(); > > > timecondition2 = tn2 >= 180001; > > > > > > Buy = Cross( MACD( fa, sa ) , Signal( fa, sa, sig ) ); > > > Sell = Cross( Signal( fa, sa, sig ), MACD( fa, sa ) ); > > > > > > Short = Sell; > > > Cover = Buy; > > > > > > Buy = Buy AND timecondition; > > > Short = Short AND timecondition; > > > //Sell = Sell OR NOT timecondition; > > > //Cover = Cover OR NOT timecondition; > > > > > > if( LastValue( Buy AND timecondition2 ) ) > > > > > > { > > > ApplyStop( 2, 2, 1, 100, False, 1 ); > > > } > > > > > > PositionSize = MarginDeposit = 1; > > >
