Even after a search for examples, I wonder if code can be executed when a button is pressed.
With this code, only the last message appear even when in trading hours.
Can I put some code or should it be a function?
Cheers
Andrei
function callClose_position(nButtonPressed, position, now, day_open, day_close, s_name, s_type, s_exp, s_right, s_strike, s_exch, s_curr, num_contracts)
{
if ( getButtonPressed( nButtonPressed ) == 1 )
{
if ((now >= day_open) && (now < day_close))
{
if (position == LONG)
{
dots5.call("ClosePosition", s_name, s_type, s_exp, s_right, s_strike, s_exch, s_curr, num_contracts);
drawShapeRelative(0, high()+0.25, Shape.UPARROW, null, Color.yellow, Shape.ONTOP, BLBarOffset+"EOD Long");
}
else if (position == SHORT)
{
dots5.call("ClosePosition", s_name, s_type, s_exp, s_right, s_strike, s_exch, s_curr, num_contracts);
drawShapeRelative(0, low()-0.25, Shape.DOWNARROW, null, Color.yellow, Shape.ONTOP, BLBarOffset+"EOD Short");
}
else if (position == NONE)
log_msg("No position to close...");
}
else
log_msg("Can't close a position outside the trading hours..."); <==== only this appear
}
return null;
}
With this code, only the last message appear even when in trading hours.
Can I put some code or should it be a function?
Cheers
Andrei
function callClose_position(nButtonPressed, position, now, day_open, day_close, s_name, s_type, s_exp, s_right, s_strike, s_exch, s_curr, num_contracts)
{
if ( getButtonPressed( nButtonPressed ) == 1 )
{
if ((now >= day_open) && (now < day_close))
{
if (position == LONG)
{
dots5.call("ClosePosition", s_name, s_type, s_exp, s_right, s_strike, s_exch, s_curr, num_contracts);
drawShapeRelative(0, high()+0.25, Shape.UPARROW, null, Color.yellow, Shape.ONTOP, BLBarOffset+"EOD Long");
}
else if (position == SHORT)
{
dots5.call("ClosePosition", s_name, s_type, s_exp, s_right, s_strike, s_exch, s_curr, num_contracts);
drawShapeRelative(0, low()-0.25, Shape.DOWNARROW, null, Color.yellow, Shape.ONTOP, BLBarOffset+"EOD Short");
}
else if (position == NONE)
log_msg("No position to close...");
}
else
log_msg("Can't close a position outside the trading hours..."); <==== only this appear
}
return null;
}
Comment