NexusFi: Find Your Edge


Home Menu

 





Coding problem, Multicharts.net, Using function entry point values as exit point


Discussion in Traders Hideout

Updated
    1. trending_up 7,258 views
    2. thumb_up 4 thanks given
    3. group 2 followers
    1. forum 10 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
shamanov
Toronto Canada
 
Posts: 9 since Jan 2018
Thanks Given: 5
Thanks Received: 1

I'm looking to use the the value of the function upon entry as the point of exit for the signal, but the correct value is not being used upon exit. Wondering if anyone has any ideas. The code below is the closest I could come to correctly implementing the signal.
________________________________________________________________________________________________
______________________________________________________________________________________________
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy {
[IOGMode(IOGMode.Disabled)]

public class working_signal : SignalObject {

private IOrderMarket buy_exit;
private IOrderMarket sell_exit;
private function_profit_target value;
private int counter;



public working_signal(object _ctx):base(_ctx)
{

counter = 0;








}
protected override void Create() {
// create variable objects, function objects, order objects etc.
buy_exit = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));
sell_exit = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.BuyToCover));
value = new function_profit_target(this);
}
protected override void StartCalc() {
// assign inputs




}
protected override void CalcBar()
{

if (CurrentPosition.Side == EMarketPositionSide.Long)
{
counter = counter + 1;
if ((Bars.Close[0] - this.EntryPrice(0)) >= (value[counter - 1]))
{
buy_exit.Send();
counter = 0;
}
}
else if (CurrentPosition.Side == EMarketPositionSide.Short)
{
counter = counter + 1;
if ((Bars.Close[0] - this.EntryPrice(0)) <= ((-1) * value[counter - 1])
{
sell_exit.Send();
counter = 0;
}
}

}
}
}
_______________________________________________________________________________________________
_______________________________________________________________________________________________


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
UCL Final Kicks Off at Noon ET: PSG at 56.5% as Iran May …
Prediction Markets & Event Contracts
Memorandum Watch: How the 60-Day MOU Framework Makes May …
Prediction Markets & Event Contracts
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
Iran Talks Final Stages -- Two VLCCs Exit Hormuz, Record …
Traders Hideout
Iran and Israel Stand Down: What $9M in Peace Contracts …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643


shamanov,

it's hard to tell without knowing the code for function_profit_target, but when you debug your code value show the expected value on the current bar?

Regards,

ABCTG


Follow me on X Reply With Quote
Thanked by:
  #4 (permalink)
shamanov
Toronto Canada
 
Posts: 9 since Jan 2018
Thanks Given: 5
Thanks Received: 1

ABCTG,

function_profit_target shows the expected value on the current bar within an indicator, is there any way to find value[counter - 1] within the signal?


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

shamanov,

I would suggest to print the values inside the signal, so you know what values your code actually sees.

Without knowing your function code I can't really tell. One way that will work is storing the result for the current bar in a VariableSeries variable and access the previous bar's values this way.

Regards,

ABCTG


Follow me on X Reply With Quote
Thanked by:
  #6 (permalink)
shamanov
Toronto Canada
 
Posts: 9 since Jan 2018
Thanks Given: 5
Thanks Received: 1

The printed values that the profit target is utilizing are the values one bar after the entry bar.


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

shamanov,

is this what you are expecting? If so, the VariableSeries approach should work.

Regards,

ABCTG


Follow me on X Reply With Quote
Thanked by:
  #8 (permalink)
shamanov
Toronto Canada
 
Posts: 9 since Jan 2018
Thanks Given: 5
Thanks Received: 1

No, I'm trying to utilize the profit target values one bar before, i.e. the same bar as entry.


Reply With Quote
  #9 (permalink)
shamanov
Toronto Canada
 
Posts: 9 since Jan 2018
Thanks Given: 5
Thanks Received: 1

I figured it out, so to conclude the post here is the code that works:

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy {
[IOGMode(IOGMode.Disabled)]
[CalcAtOpenNextBar(true)]

public class working_signal : SignalObject {

private IOrderMarket buy_exit;
private IOrderMarket sell_exit;
private function_profit_target value;
private int counter;



public working_signal(object _ctx):base(_ctx)
{

counter = 0;








}
protected override void Create() {
// create variable objects, function objects, order objects etc.
buy_exit = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));
sell_exit = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.BuyToCover));
value = new function_profit_target(this);
}
protected override void StartCalc() {
// assign inputs




}
protected override void CalcBar()
{

if (CurrentPosition.Side == EMarketPositionSide.Long)
{
counter = counter + 1;
if ((Bars.Close[0] - this.EntryPrice(0)) >= (value[counter]))
{
buy_exit.Send();
counter = 0;
}
}
else if (CurrentPosition.Side == EMarketPositionSide.Short)
{
counter = counter + 1;
if ((Bars.Close[0] - this.EntryPrice(0)) <= ((-1) * value[counter])
{
sell_exit.Send();
counter = 0;
}
}

}
}
}


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


shamanov,

thank you for the update.

Regards,

ABCTG


Follow me on X Reply With Quote




Last Updated on January 19, 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