NexusFi: Find Your Edge


Home Menu

 





Exit all positions at last bar before market close with Renko chart type


Discussion in MultiCharts

Updated
      Top Posters
    1. looks_one alex20037 with 4 posts (0 thanks)
    2. looks_two ABCTG with 2 posts (0 thanks)
    3. looks_3 crescendo with 1 posts (0 thanks)
    4. looks_4 maryfromcolorado with 1 posts (0 thanks)
    1. trending_up 1,916 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Exit all positions at last bar before market close with Renko chart type

  #1 (permalink)
 alex20037 
Miami Lakes
 
Experience: Beginner
Platform: Multicharts
Broker: Interactive Brokers
Trading: Emini ES
Posts: 19 since Oct 2016
Thanks Given: 2
Thanks Received: 3

I am trying to automatically close all open positions at last bar before market closes (4pm EST), but in a Renko chart type, because it is time independent then doesn't work. Works fine for regular candle chart. I guess there should be a way to do this. Any help appreciated please, this is the relevant portion of the code I have:

using System;

namespace PowerLanguage.Strategy {
[IOGMode(IOGMode.Enabled)]
public class Custom_Strat: SignalObject {
public Custom_Strat(object _ctx):base(_ctx){
}

private IOrderMarket bto, sto, btc, stc;
private TimeSpan exitTime;

[Input]
public string XTime { get; set; }

private IOrderMarket buy_order;
protected override void Create() {
bto = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
sto = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.SellShort));
btc = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.BuyToCover));
stc = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));

XTime = "15:55";
}
protected override void StartCalc() {

exitTime = ConvertToTime(XTime);
}
protected override void CalcBar(){

if (TimeToExit()) {
if (StrategyInfo.MarketPositionAtBroker < 0) {
btc.Send(CurrentPosition.OpenLots);
}
if (StrategyInfo.MarketPositionAtBroker > 0) {
stc.Send(CurrentPosition.OpenLots);
}
}
}

private TimeSpan ConvertToTime(string timeToConvert) {
DateTime dt = DateTime.ParseExact(timeToConvert, "H:mm",
System.Globalization.CultureInfo.InvariantCulture);

return dt.TimeOfDay;
}

private bool TimeToExit() {
// Else, when backtesting, use the bar time
if (Bars.TimeValue.TimeOfDay >= exitTime)
return true;
else
return false;
}
}
}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Looking for an MQL4 MetaTrader programmer/coder
The Elite Circle
Ninja Trader 8 Drawing Tools Wanted
NinjaTrader
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Request for MACD with option to use different MAs for fa …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
60 thanks
NexusFi site changelog and issues/problem reporting
46 thanks
Battlestations: Show us your trading desks!
34 thanks
GFIs1 1 DAX trade per day journal
31 thanks
What percentage per day is possible? [Poll]
20 thanks

  #2 (permalink)
maryfromcolorado
Denver CO USA
 
Posts: 32 since Sep 2016
Thanks Given: 0
Thanks Received: 13

Just use the function

If CurrentTime > 1500 Then
return true;

it uses your local computer time though not the broker.

Reply With Quote
  #3 (permalink)
 alex20037 
Miami Lakes
 
Experience: Beginner
Platform: Multicharts
Broker: Interactive Brokers
Trading: Emini ES
Posts: 19 since Oct 2016
Thanks Given: 2
Thanks Received: 3



maryfromcolorado View Post
Just use the function

If CurrentTime > 1500 Then
return true;

it uses your local computer time though not the broker.

Thank you very much for your help. The problem is the Renko bars, so even if the function returns true now, the order to close won't be sent until next bar, which could be another 5, 10 minutes. I think another way to ask is, what would be best way to have the strategy send the order to close right after that function returns true, without waiting for the next bar or waiting for the current bar to finish?
Thanks again.

Started this thread Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623


alex20037 View Post
The problem is the Renko bars, so even if the function returns true now, the order to close won't be sent until next bar, which could be another 5, 10 minutes.

Why? Your code uses IOG and you send orders "market next bar" which will be the next tick when IOG is enabled. In realtime the order should be triggered on the tick that detects the time condition as being valid.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #5 (permalink)
 alex20037 
Miami Lakes
 
Experience: Beginner
Platform: Multicharts
Broker: Interactive Brokers
Trading: Emini ES
Posts: 19 since Oct 2016
Thanks Given: 2
Thanks Received: 3

My apologies for leaving that line of code there please. The problem is that if IOG would be applied globably, all orders would be triggered then next tick. But I would like normal orders to be sent at next bar, then only at next tick if that time is reached.

Sent using the NexusFi mobile app

Started this thread Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

alex20037,

you will likely have to use IOG when you want to be able to close a trade intrabar. You could rework your code, so that the other orders are only issued at the end of a bar.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #7 (permalink)
 alex20037 
Miami Lakes
 
Experience: Beginner
Platform: Multicharts
Broker: Interactive Brokers
Trading: Emini ES
Posts: 19 since Oct 2016
Thanks Given: 2
Thanks Received: 3


ABCTG View Post
alex20037,

you will likely have to use IOG when you want to be able to close a trade intrabar. You could rework your code, so that the other orders are only issued at the end of a bar.

Regards,

ABCTG


Got it, I think I can try to work it out this way.

Thanks everyone.

Started this thread Reply With Quote
  #8 (permalink)
 crescendo 
Newark DE
 
Experience: Advanced
Platform: Multicharts
Trading: the Future
Posts: 4 since Dec 2015
Thanks Given: 0
Thanks Received: 0

Have the exit session be timed slightly before close, put it in a separate signal script, and have that signal be IOG on. IOG should be able to be default OFF via program, and individually ON or OFF in signals themselves for signal calculation.

Reply With Quote





Last Updated on November 15, 2016


© 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